Discussion Locked

Access97 Sort Query

0 helpful
6 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.
I have a date field of dd/mm/yy which I would like to sort. I would like to sort it by the month, but when I do a sort form within a query it always sorts by the year. can anyone suggest to sort by the month.

6 replies

by exjc

In the query you wish to sort by add a column that uses the Month() function so it looks like this:
Month: Month(MyDateField)
Where MyDateField is the name of the date field you want to sort by. This puts only the number of the month from the datefield so you can use the sort criteria to sort it (acsending or descending) while excluding the year.

by exjc

ps - you will need to remove the sort criteria from the original date field if that is still in place, and only sort it by the new "month" field.

by roc180

Use the DatePart(interval,date) function from within your Order By to sort the data by month. The following SQL will accomplish what you want:

SELECT dt
FROM Table1
ORDER BY DatePart("m",[dt]);

Good Luck

Neal Martinelli

This discussion is closed to new replies.