SQL: First and Last Day of Next Month
The following SQL code is an example of retrieving the first day and the last day of next month:
-- first day of next month
SELECT dateadd(mm,0,DATEADD(mm, DATEDIFF(m,0,GETDATE())+1,0))
-- last day of next month
SELECT dateadd(dd,-1,DATEADD(mm, DATEDIFF(m,0,GETDATE())+2,0))
SQL: SQL: First and Last Day of the Current Month
The following SQL code is an example of retrieving the first day and the last day of the current month:
-- first day of current month
SELECT DATEADD(mm, DATEDIFF(mm,0,GETDATE()),0)
-- last day of current month
SELECT DATEADD(dd,-1,DATEADD(mm, DATEDIFF(mm,0,GETDATE())+1,0))
SQL: First and Last Day of Current Year
The following SQL code is an example of retrieving the first day and the last day of the current year:
-- first day of current year
SELECT DATEADD(yy, DATEDIFF(yy,0,GETDATE()),0)
-- last day of current year
SELECT DATEADD(dd,-1,DATEADD(yy, DATEDIFF(yy,0,GETDATE())+1,0))