cool breeze
cool breeze

Reputation: 4811

Given a YEAR, how to get the start of the year

I have the year I want in a variable

DECLARE @CURRENT_YEAR AS INT
SET @CURRENT_YEAR = 2016

Now I want to beginning of the year for the year @Current_Year

How can I do this without parsing a date that I build using a varchar?

Upvotes: 0

Views: 102

Answers (2)

Sean Lange
Sean Lange

Reputation: 33571

This will get the first date of the current year.

select dateadd(yy, datediff(yy, 0, GETDATE()), 0)

--EDIT--

Since you are obviously on a version earlier than 2012 when DATEFROMPARTS was introduced you could use a little math.

DECLARE @CURRENT_YEAR AS INT 
SET @CURRENT_YEAR = 2016

select DATEADD(year, @Current_Year - 1900, 0)

Upvotes: 3

Jakub Lortz
Jakub Lortz

Reputation: 14896

You can use DATEFROMPARTS function

SELECT DATEFROMPARTS (@CURRENT_YEAR, 1, 1)

Upvotes: 5

Related Questions