Query SQL statements at the beginning of the year, at the end of last year, at the beginning of next year, and at the end of next year
Query SQL statements at the beginning of the year, at the end of last year, at the beginning of next year, and at the end of next year
Query SQL statements at the beginning of the year, at the end of last year, at the beginning of next year, and at the end of next year
-- Annual computing
Declare @ date datetime
Set @ date = getdate ()
-- Calculate the first day of the year of the given date at the beginning of the year
Select dateadd (year, datediff (year, 0, @ date), 0) as 'Day of the year'
-- Calculate the last day of the year of the given date at the end of the year.
Select dateadd (year, datediff (year,-1, @ date),-1) as 'last day of the year'
-- Calculate the first day of the year in which the given date is located at the beginning of the previous year.
Select dateadd (year, datediff (year,-0, @ date)-) as 'Day of the previous year of the year'
-- Calculate the last day of the year at the end of the previous year
Select dateadd (year, datediff (year, 0, @ date),-1) as 'the last day of the previous year'
-- Calculate the first day of the next year in the year of the given date.
Select dateadd (year, 1 + datediff (year, 0, @ date), 0) as 'Day of the next year of the year'
-- Calculate the last day of the next year at the end of the next year
Select dateadd (year, 1 + datediff (year,-1, @ date),-1) as 'the last day of the next year'
Go