Click here to Skip to main content
15,914,447 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
i Need a month (in int data type suppose for Jan- 1, Fab- 2 etc) from mm/dd/yyyy by using sql 2005
Posted

example:
SQL
select DATEPART(month,'12/02/2012')

this returns 12 as month . for more refer:http://www.sqlservercurry.com/2008/03/how-to-extract-year-month-day-hour.html[^]
 
Share this answer
 
v2
Comments
ProEnggSoft 30-Mar-12 2:00am    
To the point. +5
Use MONTH function

SQL
SELECT MONTH('10/23/2010') Month

Result

SQL
Month
-----
10
 
Share this answer
 
Comments
Mas11 28-Mar-12 8:17am    
Exactly bro.. but i have solved this at the same day.. but thanks for your answer..
Refer the following url to Convert date in different format.
I think it is useful to customize in lot of ways.

http://www.sqlusa.com/bestpractices2005/centurydateformat/
 
Share this answer
 
T-SQL CONVERT and CAST functions plays a vital role in transforming string date. You can customize in lot of ways as: http://www.sqlusa.com/bestpractices/datetimeconversion/[^]
 
Share this answer
 
Comments
Saral S Stalin 26-Mar-12 0:14am    
He just want to get the month and do not need any conversion.

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