TSQL : Convert a Year to a Datetime

Quick snippet to generate a datetime value where you only have a year to work with. Creates a datetime value set to the 1st day of the year.

DECLARE @Year int
SET @Year = 2010
SELECT CONVERT(datetime, CONVERT(varchar(8),@Year*10000+101))

This compilation of date possibilities is also really cool – though not as cool as Dan Aykroyd…

About AussieBICG

Connect with me here https://au.linkedin.com/in/aussiebicg

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s