I don't like casting strings to dates. Neither should you.
If you using SQL Server 2012 or later then you can use the answersuggested by Paul Williams i.e. DateFromParts
or similar functions.
For earlier versions here's the method I would use:
DECLARE @Year int;
DECLARE @JanDate datetime;
SET @Year = 2014;
SET @JanDate = DateAdd(dd, 25 - 1, DateAdd(yy, @Year - 1900, '1900-01-01'));
SELECT @JanDate;
It might seem overly complicated to some, but the way in which it performs the action is much more pleasing [to me] as it uses nothing but dates and integers.
Starting at SQL Servers base date 1900-01-01
we add on the number of years supplied (correcting by 1900 years ;-)
)
Then we add on the number of days (again, a correction of 1 day is required as the date we're working with is already the 1st of the month so adding 25 = 26, not the 25 we want).
Here's some supplementary code that you might find useful. Supply it any year, month and day it it will work it out for you.
If a user supplies "invalid" values (e.g. 2014-02-31
- there is no 31st of February) then the function will not fail, unlike a text to date casting. Instead it will provide the result 2014-03-03
which is 31 days after 1st Feb.
This logic might not please some people but it has always worked for me.
Enough waffling, here's the code:
DECLARE @y int
, @m int
, @d int;
SET @y = 2014;
SET @m = 6;
SET @d = 22;
SELECT DateAdd(dd, @d - 1, DateAdd(mm, @m - 1, DateAdd(yy, @y - 1900, '1900-01-01')));
-End transmission-