You can try converting the date on the fly
...ORDER BY str_to_date(received, '%d-%m-%Y %H:%i:%s')
but this sounds like a rather bad idea to me. Why not to store dates in the native format, DATETIME
?
Question
I'm busy with creating a message system for users. But I've some trouble with the european date format.
In my MySQL DB I've the date's stored like this :
date('d-m-Y H:i:s');
For examle 07-04-2014 22:03:41 and 08-04-2014 19:32:23
But when I tried to order them by using ORDER BY received DESC
(which works fine with date('Y-m-d H:i:s');
it doesn't show the messages in the right order.
For example it shows 22-03-2014 as first and 08-04-2014 as latest.
Could someone help me out?
I've already tried date_default_timezone_set('Europe/London');
but that isn't working.
EDIT : Here's my Query btw;
$stmt = $con->prepare("SELECT * FROM messages WHERE ID_receiver='$KlantID' AND ticket_nummer='$Ticket_Nmr' ORDER BY `received` DESC");
Solution
You can try converting the date on the fly
...ORDER BY str_to_date(received, '%d-%m-%Y %H:%i:%s')
but this sounds like a rather bad idea to me. Why not to store dates in the native format, DATETIME
?