Wednesday 26 October 2011

Sort MySQL by DD-MM-YYYY without altering data

Sort MySQL by DD-MM-YYYY without altering data

I have a dump of a database that I need to find patterns in.

The trouble is that all columns are defined as varchar(100) and now I have trouble sorting by date. If all dates where following the system friendly YYYYMMDD format all would be well but they follow the local convention of DD-MM-YYYY

I could easily cope with altering the dates using sed or awk on the dumpfile, but I am not allowed to alter the data in any way.


So I'm looking for a way to tell MySQL to treat the Foo_Time column in the table as a date field formatted as DD-MM-YYYY and thus sort 9-9-2011 before 1-10-2011

No comments:

Post a Comment