SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Wizard gold trophysilver trophy
    Join Date
    Nov 2000
    Location
    Switzerland
    Posts
    2,479
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Sorting on MySQL DATE fields

    Have always used TIMESTAMP fields for sorting a table by date. Trouble is to display a easy to read date, TIMESTAMP is a problem, so I've been adding a seperate DATE field for storing results of the PHP date() function.

    Question is, is there a cunning way to sort on a DATE field, and skip using the TIMESTAMP?

  2. #2
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Whats the problem? ORDER BY datefield or ORDER BY datefield DESC

    Consequently

    You can use DATE_FORMAT() on your timestamp fields, there is no reason to store two dates.


    see the manual for formatting options.

    http://mysql.he.net/documentation/my...e.html#IDX1298
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  3. #3
    SitePoint Wizard gold trophysilver trophy
    Join Date
    Nov 2000
    Location
    Switzerland
    Posts
    2,479
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Alright! Many thanks Freddy.

    Last time I tried was a while ago and may have made a mistake somewhere - somehow was getting a sort which began at the day of the month end rather then beginning with the year.


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
  •