NoDoze Posted January 7, 2009 Share Posted January 7, 2009 How would you do a mysql query to post the most recent date and time in a table? ...only that entry. Thanks. Link to comment https://forums.phpfreaks.com/topic/139924-query-most-recent-record-by-date-and-time/ Share on other sites More sharing options...
Maq Posted January 8, 2009 Share Posted January 8, 2009 ORDER BY date DESC LIMIT 1; Link to comment https://forums.phpfreaks.com/topic/139924-query-most-recent-record-by-date-and-time/#findComment-732101 Share on other sites More sharing options...
NoDoze Posted January 9, 2009 Author Share Posted January 9, 2009 ok, something wierd is going on... I have the code line like you have above, like this: $sql = "SELECT * FROM hicks ORDER BY date DESC LIMIT 1"; But it's not pulling the most recent one... Link to comment https://forums.phpfreaks.com/topic/139924-query-most-recent-record-by-date-and-time/#findComment-733575 Share on other sites More sharing options...
NoDoze Posted January 9, 2009 Author Share Posted January 9, 2009 ok, I added another column for timestamp and having it use that to pull the most recent. For some reason I think the date XX-XX-XX and XXXX hour format is having issues. Link to comment https://forums.phpfreaks.com/topic/139924-query-most-recent-record-by-date-and-time/#findComment-733646 Share on other sites More sharing options...
corbin Posted January 10, 2009 Share Posted January 10, 2009 If the column is a string datatype (char to be more correct) it will sort oddly (well, not oddly, but not what you would expect). You should really use a date or datetime column for dates or dates including time. Link to comment https://forums.phpfreaks.com/topic/139924-query-most-recent-record-by-date-and-time/#findComment-733822 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.