Link to home
Start Free TrialLog in
Avatar of mugsey
mugseyFlag for United Kingdom of Great Britain and Northern Ireland

asked on

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
Avatar of Mortaza Doulaty
Mortaza Doulaty
Flag of United Kingdom of Great Britain and Northern Ireland image

Try this:

ORDER BY CAST(YouDateTimeField AS sql_variant)

Open in new window

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
ASKER CERTIFIED SOLUTION
Avatar of Mortaza Doulaty
Mortaza Doulaty
Flag of United Kingdom of Great Britain and Northern Ireland 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