I'm declaring some months and dates and need help on getting the first and last date of this month last year.
So far I have the following.
DECLARE @today date Set @today = cast (getdate() as date)
DECLARE @firstdaylastmonth date Set @firstdaylastmonth = DATEADD(month, DATEDIFF(month, 0, @today)-1, 0)
DECLARE @lastdaylastmonth date SET @lastdaylastmonth = DATEADD(s,-1,DATEADD(mm, DATEDIFF(m,0,@today),0))
DECLARE @lastdaythismonth date SEt @lastdaythismonth = DATEADD(s,-1,DATEADD(mm, DATEDIFF(m,0,@today)+1,0))
-- DECLARE @firstdaythismonthlastyear SET
-- DECLARE @lastdaythismonthlastyear SET
Select
@today,
@firstdaylastmonth,
@lastdaylastmonth,
@lastdaythismonth
-- @firstdaythismonthlastyear
-- @lastdaythismonthlastyear
But am having trouble finding the last 2 declarations. Help appreciated.