sql server - First and last day of this month last year -


i'm declaring months , dates , need on getting first , last date of month last year.

so far have following.

declare @today date set @today = cast (getdate() 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 having trouble finding last 2 declarations. appreciated.

you can use eomonth ( start_date [, month_to_add ] ) function sql server 2012 , above.


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -