Q:

Getting the result of a MySql query order by date when the date field can contain strings differents than dates

I have a date field on my Sql table that is actually a text field, thats because there sometimes I save dates like 10/28/2011 and sometimes strings like present.

It is possible without touching the table structure, and maybe just with the sql query having the result correct organanized by date? Where present is the max value and then the dates in decreasing order.

A:

If you really can't sort the data type out on those string date columns then this might help:
select t.*,
case when date_end = 'present' then curdate()
else convert(concat(substr(date_end,7,4),'-',substr(date_end,1,2),'-'    ,substr(date_end,4,2)),date) end as "realDate"
from myTable t
order by "realDate" desc;

Right. I'm off to go and say 100 Hail Marys to the MySQL database god now. Ugh.

