SQL Statements for First and Last Date of a Month and Week

by Bill Dowling 17. June 2013 11:26
The following tsql statements can be used to get the first and last dates in a month. DECLARE @InputDate DATE=GETDATE() SELECT DAY(DATEADD(MONTH,DATEDIFF(MONTH,-1,@InputDate),-1)) AS DaysInMonth SELECT DATEADD(M,DATEDIFF(M, 0, @InputDate), 0) AS FirstDate SELECT DATEADD(D,-1,DATEADD(M,DATEDIFF(M,0,@InputDate)+1,0)) AS LastDate SELECT DATEADD(S,-1,D... [More]


SQL Coding Examples

About the author

Bill Dowling has been a VB and .Net programmer for as long as he can remember.

Month List