Forum Moderators: open
I have a mysql database with columns id,productname,year,month,day .
I want to sort with year,month,day to have the more recent products first .
I'm using :
select id,year,month,day from table order by year desc,month desc,day desc
My problem is that I have records for month and day like '06' but also like '6'. ('05' and '5' ,etc)
And my query returns something like :
2007 6 6
2007 6 5
........
2007 06 06
I want it to be
2007 6 6
2007 06 06
..
2007 6 5
.........
Do you have any ideas? Thanks.
You can even change day month year to one field `date` DATE;
then you won't have any problems with date sorting, nor checking (you will never have a date like 2007-29-87
And then sorting is easier as well, and day you can still retrieve with function DAY:
SELECT DAY(`date`);
More date and time functions you can find here:
[dev.mysql.com...]
Regards
Michal