Selecting specific dates - T- SQL

i need a query that will let me select distinct months, from a column that contains the date in the format: 10/20/2006 12:00:00 AM



sammaellAsked:
Who is Participating?
 
Scott PletcherConnect With a Mentor Senior DBACommented:
You can use:

SELECT MONTH(date), YEAR(date)
WHERE MONTH(date) = 10
AND YEAR(date) = 2006
0
 
SireesCommented:
You can use Month function

from BOL

MONTH
Returns an integer that represents the month part of a specified date.

Syntax
MONTH ( date )
0
 
Scott PletcherSenior DBACommented:
However, it's better to use a date range expression that SQL can use to search an index (if one exists now or in the future):

SELECT ...
FROM ...
WHERE date >= '20061001' AND date < '20061101'  --to get Oct 2006 only
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.