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 2005 Forums
 Transact-SQL (2005)
 How can know the Ending day of the month

Author  Topic 

js.reddy
Yak Posting Veteran

80 Posts

Posted - 2009-01-09 : 06:18:15
Hi guys,
How can know the ending day of the given month.

for example

select getdate() as currentdate, '---', ' ' as EndingDay
the result should be :
2009-01-09 16:45:08.090 --- 31


Regards
Js.Reddy

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-01-09 : 06:23:29
[code]select dateadd(mm,datediff(mm,0,getdate())+1,0)-1[/code]
Go to Top of Page

js.reddy
Yak Posting Veteran

80 Posts

Posted - 2009-01-09 : 06:37:06
Thank You Visakh16

quote:
Originally posted by visakh16

select dateadd(mm,datediff(mm,0,getdate())+1,0)-1


Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-01-09 : 06:40:25
welcome
Go to Top of Page

Skorch
Constraint Violating Yak Guru

300 Posts

Posted - 2009-01-09 : 12:50:17
This may be just a tiny bit simpler:
SELECT DATEADD(mm,DATEDIFF(mm,-1,GETDATE()),-1)
Go to Top of Page

Nageswar9
Aged Yak Warrior

600 Posts

Posted - 2009-01-09 : 23:07:38
SELECT DATEADD(d, -DAY(DATEADD(m,1,GETDATE())),DATEADD(m,1,GETDATE())) AS 'Last day of the month'
Go to Top of Page
   

- Advertisement -