[thelist] mysql: monthname results order
Rob Smith
rob.smith at THERMON.com
Fri Mar 14 14:31:45 CST 2003
SELECT DISTINCT MONTHNAME(date) AS month FROM date WHERE (date <> '0000-00-
00') ORDER BY month ASC
...Of course its going to return in Alphabetical order. (see ORDER BY
clause)
You could possibly say something like:
SELECT DISTINCT MONTHNAME(date) AS month_chosen FROM date WHERE (date <>
'0000-00-00') ORDER BY DATEPART(month_chosen, GETDATE())
This just might return them in the correct calendar order. the GETDATE()
portion will return the number of the month as it appears in the date (i.e.
1/21/2003 will return 1)
Here are the other elements of the DATEPART() function. Note my version of
your SQL query has the word 'month' changed as 'month' may be a key word of
the DATEPART() function:
year yy, yyyy
quarter qq, q
month mm, m
dayofyear dy, y
day dd, d
week wk, ww
weekday dw
hour hh
minute mi, n
second ss, s
millisecond ms
HTH!,
Rob.Smith
More information about the thelist
mailing list