DECLARE @Today DATETIME
SELECT @Today = '6/17/2007'
Select 'Get First Day of a Month Using SQL Query'
SELECT DATEADD(dd,-(DAY(DATEADD(mm,1,@Today))-1),DATEADD(mm,-3,@Today))
--Value = 2007-03-01 00:00:00.000
SELECT DATEADD(dd,-(DAY(DATEADD(mm,1,@Today))-1),DATEADD(mm,-2,@Today))
--Value = 2007-04-01 00:00:00.000
SELECT DATEADD(dd,-(DAY(DATEADD(mm,1,@Today))-1),DATEADD(mm,-1,@Today))
--Value = 2007-05-01 00:00:00.000
SELECT DATEADD(dd,-(DAY(DATEADD(mm,1,@Today))-1),DATEADD(mm,0,@Today))
--Value = 2007-06-01 00:00:00.000
SELECT DATEADD(dd,-(DAY(DATEADD(mm,1,@Today))-1),DATEADD(mm,1,@Today))
--Value = 2007-07-01 00:00:00.000
SELECT DATEADD(dd,-(DAY(DATEADD(mm,1,@Today))-1),DATEADD(mm,2,@Today))
--Value = 2007-08-01 00:00:00.000
SELECT DATEADD(dd,-(DAY(DATEADD(mm,1,@Today))-1),DATEADD(mm,3,@Today))
--Value = 2007-09-01 00:00:00.000
Select 'Get Last Day of a Month Using SQL Query'
SELECT DATEADD(dd, -DAY(DATEADD(m,1,@Today)), DATEADD(m,-2,@Today))
--Value = 2007-03-31 00:00:00.000
SELECT DATEADD(dd, -DAY(DATEADD(m,1,@Today)), DATEADD(m,-1,@Today))
--Value = 2007-04-30 00:00:00.000
SELECT DATEADD(dd, -DAY(DATEADD(m,1,@Today)), DATEADD(m,0,@Today))
--Value = 2007-05-31 00:00:00.000
SELECT DATEADD(dd, -DAY(DATEADD(m,1,@Today)), DATEADD(m,1,@Today))
--Value = 2007-06-30 00:00:00.000
SELECT DATEADD(dd, -DAY(DATEADD(m,1,@Today)), DATEADD(m,2,@Today))
--Value = 2007-07-31 00:00:00.000
SELECT DATEADD(dd, -DAY(DATEADD(m,1,@Today)), DATEADD(m,3,@Today))
--Value = 2007-08-31 00:00:00.000
SELECT DATEADD(dd, -DAY(DATEADD(m,1,@Today)), DATEADD(m,4,@Today))
--Value = 2007-09-30 00:00:00.000