Posts
509
Comments
440
Trackbacks
1
T-SQL to get last day of the month

From: http://vyaskn.tripod.com/code.htm#lastday

The logic behind this 'last day of the month' calculations is that you get the month part of a given date, add one to it, there by getting to the next month. Then subtract 1 day from the first of that month. This whole Thing can be written in one line and here it is:

SELECT DAY(DATEADD(d, -DAY(DATEADD(m,1,GETDATE())),DATEADD(m,1,GETDATE())))

posted on Tuesday, March 29, 2005 2:18 PM
Comments
# re: T-SQL to get last day of the month
Divya
9/14/2007 8:06 AM
its nt working.. it shows an error tht dateadd is an invalid character...
Gravatar
# re: T-SQL to get last day of the month
Sheryar Nizar
9/22/2008 3:52 AM
SELECT DAY(DATEADD(d, -DAY(DATEADD(m,1,GETDATE())),DATEADD(m,1,GETDATE())))
works fine..
Sheryar Nizar

Post Comment

Title *
Name *
Email
Url
Comment *  
Please add 8 and 4 and type the answer here: