views:

414

answers:

3

I am trying to use the actual numerical value for the month on a sql query to pull results. Is there any way to do this without having a function to change the numbers to actual month names, then back to month numbers? The following code works for Names, what works for numbers?

datename(month,(convert(datetime,DTSTAMP)))= 'October'

+1  A: 

month,(convert(datetime,DTSTAMP)) should do it, but why on earth are you not storing the data correctly as a datetime to begin with? All that additional conversion stuff to use the dates adds unnecessary load to your server and slows down your application.

HLGEM
I just came into this company and that is how they stored it...
A: 

Datepart is an alternative to the month command and it is more flexable as you can extract other parts of the date.

DATEPART(mm, convert(datetime,DTSTAMP))
Jamal Hansen
A: 

Gets Month Number of Date

CONVERT(VARCHAR(2) ,DTSTAMP ,110)