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

i have a feild which stores datetime type values
2011-11-30 00:00:00.000

I want to retrieve month number from this .
I need month number for some other sql-query . i tried using substring but it gives me error
SQL
Argument data type datetime is invalid for argument 1 of substring function.

Please tell me how to retrieve it!!!!
Posted
Comments
Chandrashekar SK 11-Jun-12 6:49am    
Which programming language you're using??
VJ Reddy 11-Jun-12 7:26am    
Thank you for accepting the solution :)

The DATEPART(mm,date) function can be used for this purpose as explained here
http://www.w3schools.com/sql/func_datepart.asp[^]
 
Share this answer
 
v2
Comments
Manas Bhardwaj 11-Jun-12 9:16am    
Accurate +5!
VJ Reddy 11-Jun-12 9:38am    
Thank you, Manas :)
Espen Harlinn 12-Jun-12 8:40am    
5'ed!
VJ Reddy 12-Jun-12 9:00am    
Thank you, Espen :)
Hi,

Are you trying to get the value '11' from the given date?
Just try this:

select MONTH('2011-11-30 00:00:00.000')

Thank You.
 
Share this answer
 

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