vBulletin Search Engine Optimization
| |||||||
| Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| ||||
| People, I am not very savy with SQL and I need help. I have a char field that contains a date and the date is in DD-MM-YYYY and I want to sort it but the sort is wrong because 01-04-2007 comes out before 10-22-2006. Is there an easy way to provide a correct sorted output list or do I need to edit my table and convert all my fields to YYYY-MM-DD before I can sort it. Any help is welcome. Thanks, Néstor :-) |
| ||||
| In the last episode (Dec 05), Nstor said: > I am not very savy with SQL and I need help. I have a char field > that contains a date and the date is in DD-MM-YYYY and I want to sort > it but the sort is wrong because 01-04-2007 comes out before > 10-22-2006. > > Is there an easy way to provide a correct sorted output list or do I > need to edit my table and convert all my fields to YYYY-MM-DD before > I can sort it. Take a look at http://dev.mysql.com/doc/refman/5.0/...functions.html and the STR_TO_DATE() function. You can use it directly in an ORDER BY clause, or better yet, create a real DATETIME column, copy your date into that, and use the new field from here on. -- Dan Nelson dnelson@allantgroup.com |
| Thread Tools | |
| Display Modes | |
|
|