SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Addict
    Join Date
    Sep 2008
    Posts
    341
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Order by 11/18/2010

    A MySql database I am working with stores dates like 11/18/2010 (varchar type).

    Can I arrange this in order?

    Would be great if they were timestamp, but they're not.

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,251
    Mentioned
    59 Post(s)
    Tagged
    3 Thread(s)
    ORDER BY STR_TO_DATE(thedate,'%d/%m/%Y')
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  3. #3
    SitePoint Guru
    Join Date
    Sep 2008
    Posts
    977
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    or, I think, make another column called date_name (or however is appropriate, without using the reserved word 'date'), and store them as a date or datetime column. then in your server-side language convert the date to ISO format , yyy/mm/dd and store it that way.

    Once it's done for all your exisiting records, you could remove the current column. Doing it this way (iso) can make date comparisons more efficieint, I think.
    (subject to confirmation from someone more knowledgable ).

  4. #4
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,251
    Mentioned
    59 Post(s)
    Tagged
    3 Thread(s)
    Quote Originally Posted by IBazz View Post
    Doing it this way (iso) can make date comparisons more efficieint, I think.
    you betcha
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"


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
  •