- This topic is empty.
Viewing 5 posts - 1 through 5 (of 5 total)
Viewing 5 posts - 1 through 5 (of 5 total)
- The forum ‘Back End’ is closed to new topics and replies.
The forums ran from 2008-2020 and are now closed and viewable here as an archive.
Hi I’m trying to output results from my database according to the latest date.
my query is:
SELECT `title` , `text` , `date_time`
FROM `post_table`
ORDER BY date DESC
LIMIT 0 , 30
Sql’s output is not according to date but to time
2013-04-09 08:09:10
2013-04-15 10:29:06
2013-04-15 10:40:36
2013-04-12 16:41:27
The order should be according to the latest date and time just like the following:
2013-04-15 10:40:36
2013-04-15 10:29:06
2013-04-12 16:41:27
2013-04-09 08:09:10
How am I going to achieve this output?
Have you seen this? http://stackoverflow.com/questions/3331690/mysql-order-by-date-and-then-by-time
Are you sure it’s just not as simple as you’re selecting a field called “date_time” and then using ORDER BY date DESC.
If you’d change it to “ORDER BY `date_time` DESC” it should work as expected, assuming your “date_time” field is a DateTime type.
Oh goodness! How crazy of me. I must have overlooked some of my researches about it.
SELECT `title` , `text` , `date_time`
FROM `post_table`
ORDER BY date_time DESC
LIMIT 0 , 30
@DanielMortzen – Yes my date_time field is actually DateTime type. I have already changed it and its working as expected. Thank you so much for the help.
Thanks as well @chrisburton
Excellent! :)