rd42
rd42

Reputation: 3594

mysql sort string as date not as string

The DB I inherited stored there dates like: yyy-mm-dd hh:mm:ss

I was hoping to sort by date in my mysql query but it is treating them like a string and sorting accordingly.

Any one know of a way to sort them as a date and not a string in the query itself?

Thanks, Robert

Upvotes: 0

Views: 2621

Answers (1)

Chris Haas
Chris Haas

Reputation: 55427

You can try casting the value to a date and sorting by that:

ORDER BY CAST(SDate As DATETIME);

Upvotes: 1

Related Questions