how to sort on datetime datatype

How can I sort on a datetime datatype

11/01/2002 09:35:19
11/01/2002 11:35:10
11/01/2002 07:35:09

order by does not give the correct results.   I need to be able to sort on date then the time part of the date
mugseyAsked:
Who is Participating?
 
Mortaza DoulatyConnect With a Mentor Commented:
But simply using ORDER BY should work...

It displays:

2002-11-01 07:35:09.000
2002-11-01 09:35:19.000
2002-11-01 11:35:10.000

Isn't this what you expect?
0
 
Mortaza DoulatyCommented:
Try this:

ORDER BY CAST(YouDateTimeField AS sql_variant)

Open in new window

0
 
jppintoCommented:
If you have the data as Date/Time format it will sort correctly. If you have your data as text it will not sort correctly.

jppinto
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.