Grow your CSS skills. Land your dream job.

Please help mysql – ORDER BY Date Desc

  • # April 15, 2013 at 12:00 am

    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?

    # April 15, 2013 at 2:59 am

    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.

    # April 15, 2013 at 5:11 am

    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

    # April 15, 2013 at 5:27 am

    Excellent! :)

Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic.

*May or may not contain any actual "CSS" or "Tricks".