--the first day of last month SELECT CONVERT(CHAR(Ten),DATEADD(Month,-1,DATEADD(DD,- Day(GETDATE())+1,GETDATE())),111) SELECT DATEADD(MM,DATEDIFF(MM,0,DateAdd(Month,-1,getdate())),0) --the last day of last month SELECT CONVERT(CHAR(Ten),DATEADD(MS,-3,DATEADD(MM,DATEDIFF(MM,0,getdate()),0)),111)+'23:59:59' Select DateAdd(MS,-3,DATEADD(MM,DATEDIFF(MM,0,getdate()),0)) --first day of the month SELECT CONVERT(CHAR(Ten),DATEADD(DD,- Day(GETDATE())+1,GETDATE()),111) SELECT CONVERT(datetime,CONVERT(Char(8),GETDATE(), -)+'1') --last day of the month SELECT CONVERT(CHAR(Ten),DATEADD(MS,-3,DATEADD(MM,DATEDIFF(M,0,getdate())+1,0)),111)+'23:59:59' Select DATEADD(d,- Day(getdate()),DateAdd(M,1,getdate())) --the last day of the next month SELECT CONVERT(CHAR(Ten),DATEADD(M,1,DATEADD(DD,- Day(GETDATE())+1,GETDATE())),111)--the last day of next monthSELECT CONVERT(CHAR(Ten),DATEADD(MS,-3,DATEADD(MM,DATEDIFF(M,0,getdate())+2,0)),111)+'23:59:59'--get the last minute of the daySelect DATEADD(SS,-1,DateAdd( Day,1,CONVERT(varchar( the) ,getdate(),102)))
Find the first and last day of the month, month, and next month in SQL Server [go]