Reputation: 777
Problem I have the last data entry in date_time for 9th of april 2013 whereas when I try to fetch in descending order from the database it is giving me 8th April 2013. Please see the image and Code below. Any help will be appriciated.
Database
Code
SELECT *
FROM data_feeds
WHERE username = '[email protected]'
AND gadget_data_type = 'Weighin'
ORDER BY STR_TO_DATE( date_time, '%D, %j %M %Y %H:%i:%s' ) DESC
LIMIT 1
Upvotes: 0
Views: 1469
Reputation: 11832
Your format for str_to_date() is wrong
You say
%D, %j %M %Y %H:%i:%s
So according to you the second value is %j. But according to Mysql docs %j is 'day of year'. https://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html
edit: you have multiple errors in the format. Try: %a, %e %b %Y %H:%i:%s
Upvotes: 0