Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 max/min day in a month

Author  Topic 

u2p_inst
Yak Posting Veteran

78 Posts

Posted - 2004-04-21 : 10:59:41
i have query like

Declare @Month as datetime
Set @Month='02/29/2004'
select
dateadd(month,1,@Month)

The result is 2004-03-29,
in the case i need get the max/min day in that month
is it possible so the result like 2004-03-31

oh

AndrewMurphy
Master Smack Fu Yak Hacker

2916 Posts

Posted - 2004-04-21 : 11:11:22
Well the min is always "1"...!!!
as for the max.....determine the 1st of the next month, and subtract 1 day from it!
Go to Top of Page

RickD
Slow But Sure Yak Herding Master

3608 Posts

Posted - 2004-04-21 : 12:11:14
--First Day of Month
select DATEADD(mm, DATEDIFF(mm,0,getdate()), 0)

--Last Day of Month
select dateadd(ms,-3,DATEADD(mm, DATEDIFF(m,0,getdate() )+1, 0))
Go to Top of Page
   

- Advertisement -