![]() |
mysql order by date
So I'm wondering about order by date but I guess this probably covers most order by questions. If you do something like
Code:
Select * from events ORDER BY date_field |
If the datatype is a date type, it is not stored as a string but as a machine readable format. How it is output is decided after the sorting is done.
|
Ok, I have no idea what you mean.
|
You can't change the format in which MySQL stores the date. However, you can always modify the format when you retrieve it from your table. MySQL will sort it in chronological order.
|
Ok but my original question still seems to be about left to right or right to left in the field being ORDER BY.
|
But I don't think you can change it from YYYY/MM/DD, can you?
|
I guess if you have inserted the data from a php statement, that was my intention. I'm sort of new to this date sorting thing and am not sure the best way to store dates really.
|
I better explain this better. I am using a javascript date picker that puts dates into a form. It uses these formats 06/23/2009 or 04.06.2009. Suggestions?
|
I'd personally store the dates as a timestamp.
|
Yes, that does make more sense. Thanks for the suggestion, I'll change my feeble code :-)
|
losing my mind
I can't see where I am screwing this up...
Code:
echo "06/27/2009 converts to: ". strtotime("06/27/2009"), "\n";Code:
06/27/2009 converts to: 1246078800 |
It is because you're using
strtotime again on an existing timestamp. |
I feel sheepish. Thanks Wildhoney!
|
| All times are GMT. The time now is 02:31 PM. |
Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0