SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Zealot matches's Avatar
    Join Date
    Aug 2006
    Posts
    196
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    basic question - order by date

    I have a mySQL DB and I want to order the query results by date. Do the field need to be unix timestamp or can it just be a date field? And what format must the day be in? ie YYYY-MM-DD etc.

    Thanks for any help.

  2. #2
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,580
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    DATE (and DATETIME, TIMESTAMP) are explicit data types in MySQL

    If the column is a DATE, DATETIME or TIMESTAMP type, then MySQL knows how to sort by the values in that column

    There are many formats MySQL can recognize when it comes to inserting the dates into the database:

    http://dev.mysql.com/doc/refman/5.0/en/datetime.html

    But that is not relevant when it comes to sorting, as the values are already there

    Code:
    SELECT ... ORDER BY your_date_column


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •