I need to create a list of unique month numbers (ie: 1- 12) from a datetime field for dates in a date range, and would like to order the month numbers by date ascending
So if I had the following dates:
- November 23, 2012
- December 2, 2012
- December 14, 2012
- November 12, 2012
- December 22, 2012
- February 4, 2013
then I would like the output to be:
- 11
- 12
- 2
The dates are all in a datetime format
I have tried both the Distinct and Group by clauses but I am struggling to find something that works.
(ie: something like 'Select distinct(month(gamedatetime)) from games order by gamedatetime asc' which now throws me an error)
Thanks, Peter
Firstly, is the field a Datetime type?
Irnocially, testing this in MS SQL your formula works. Which DBMS are you using?