Click here to Skip to main content
15,039,149 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all

how to get date format from known month and year in sql server

eg: i have to form a date using month 5 and year 2011..the new should be in format date 05/01/2011.

how to get it

Thanks in Advance
Posted

1 solution

Assuming @month = 5, and @year = 2011 and are integers:

SET DATEFORMAT dmy;
DECLARE @myDate DATETIME;
DECLARE @dateString varchar(10);
SET @dateString = CONVERT(int, @month) + '/01/' + CONVERT(int, @year);
SET @myDate = CONVERT(DateTime, @dateString);


There are probably better ways to do it, but this should work (I just typed it off the top of my head, so you may need to tweak it).
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900