I am trying to order the records from a table desc (format mm/dd/yyyy) which is of type varchar(255).
order by date
SELECT *, DATE_FORMAT(date,'%m/%d/%Y') AS reldate FROM table ORDER BY reldate DESC
This is not working.For date = 03/28/2009, reldate return as NULL.I’m a beginner in mysql so I don’t really know how to fix this.
Thanks.
(I may be misunderstanding your question. Is the date column a date or a varchar? My response is based on the assumption it’s varchar, which is what I understood.)
I think the function you’re after is STR_TO_DATE, not DATE_FORMAT. DATE_FORMAT actually does the opposite of what you desire; it goes from a date to a string, whereas you’re trying to go from a string to a date.
The bigger question is, why is this data in a VARCHAR column in the first place?