Link to home
Start Free TrialLog in
Avatar of sammaell
sammaell

asked on

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



ASKER CERTIFIED SOLUTION
Avatar of Scott Pletcher
Scott Pletcher
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Sirees
Sirees

You can use Month function

from BOL

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

Syntax
MONTH ( date )
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