-- Return Last Date of a Month
DECLARE @Month smallint
SET @Month = 1
SELECT DATEADD(Month, DATEDIFF(Month,0,getdate())+@Month, -1) as LastDateOfMonth,
DAY(DATEADD(Month, DATEDIFF(Month,0,getdate())+@Month, -1)) as LastDayOfMonth
The @Month accepts the month that needs to be added as the third parameter of the DATEADD function. You can set different values as shown below to view the last day of the month
1 - Current Month
0 - Last Month
2 - Next Month
Did you like this post?
|
|
|
||
|
|
|
|
|
|
|
subscribe via rss |
|
subscribe via e-mail |
|
|
print this post |
|
follow me on twitter |




comments
1 Response to "Find Last Day Of a Month in SQL Server 2005"That function does not return the correct values at all.
Post a Comment