Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End Please help mysql – ORDER BY Date Desc

  • This topic is empty.
Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #44119
    ajnoguerra
    Participant

    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?

    #131792
    chrisburton
    Participant
    #131794

    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.

    #131799
    ajnoguerra
    Participant

    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

    #131800

    Excellent! :)

Viewing 5 posts - 1 through 5 (of 5 total)
  • The forum ‘Back End’ is closed to new topics and replies.