MySQL Order by Date

Discussion in 'PHP' started by Kennedy, Feb 3, 2008.

  1. #1
    My dates are arranged by year-month-day (2008-02-03) in my database, but whenever I try to use ORDER BY, it orders it by month first, and not the year. I just want them in order from the most recent date to the oldest date. What I have so far is this:

    $query="SELECT * FROM vids ORDER BY vdate DESC";

    "vids" being the table name and "vdate" being the date of the entry in year-month-day. How should this code look instead?
     
    Kennedy, Feb 3, 2008 IP
  2. HuggyStudios

    HuggyStudios Well-Known Member

    Messages:
    724
    Likes Received:
    20
    Best Answers:
    26
    Trophy Points:
    165
    #2
    Store a timestamp, make sure the table is set to a INT and then you can just query the database with,

    
    SELECT * FROM `table` ORDER BY timestampfield DESC
    
    Code (markup):
     
    HuggyStudios, Feb 3, 2008 IP