0
Find Last Day of Any Month – Current Previous Next
Posted by Rajendra Prasad Panchati
on
Wednesday, June 16, 2010
Following script demonstrates the script to find last day of previous, current and next month.
ResultSet:
LastDay_PreviousMonth
———————–
2010-05-31 23:59:59.000
SELECT DATEADD(s,-1,DATEADD(mm, DATEDIFF(m,0,GETDATE()),0))
LastDay_PreviousMonth
SELECT DATEADD(s,-1,DATEADD(mm, DATEDIFF(m,0,GETDATE())+1,0))
LastDay_CurrentMonth
SELECT DATEADD(s,-1,DATEADD(mm, DATEDIFF(m,0,GETDATE())+2,0))
LastDay_NextMonthResultSet:
LastDay_PreviousMonth
———————–
2010-05-31 23:59:59.000
LastDay_CurrentMonth
———————–
2007-06-30 23:59:59.000
———————–
2007-06-30 23:59:59.000
LastDay_NextMonth
———————–
2007-07-31 23:59:59.000
———————–
2007-07-31 23:59:59.000
DECLARE @dtDate DATETIME
SET @dtDate = '06/16/2010'
SELECT DATEADD(s,-1,DATEADD(mm, DATEDIFF(m,0,@dtDate)+1,0))
LastDay_AnyMonthResultSet:
LastDay_AnyMonth
———————–
2010-06-30 23:59:59.000
More
Less