When each item is entered into the db i use the following method to insert date:
date_default_timezone_set('America/New_York');
ob_start();
$createdon = date('l, F j, Y, h:i A');
ob_get_clean();
This outputs something like:
Tuesday, May 3, 2011, 04:50 PM
This is the query:
select test_id, why_test, date_time
from the_test
where p_id = '$id'
UNION
select pencil_id, pencil_name, date_time
from pencils
where p_id = '$id'
ORDER BY 3 DESC
Now when i user the order by function it doesn’t do it properly. The dates are still being mixed up. I used order by date_time DESC.
I am using php/phpmyadmin.
Any ideas?
Storing a date as a string is wrong. You should store a date as a date.
MySQL has a selection of appropriate types relating to dates and times; I’d recommend either
TIMESTAMPorDATETIME(probably the latter; look it up in the manual to see what’s best for you).To avoid losing your existing data when you fix your table structure:
UNIX_TIMESTAMPfunction — this is a one-time copy, which might take some time;ORDER BYwill work naturally on this field, as you will now be using MySQL as it is designed to be used.