Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

mySql Changing date format for table

Options
  • 10-02-2009 11:12am
    #1
    Registered Users Posts: 3,875 ✭✭✭


    Hello In my currentg mysql databse the date fields are stored in the format
    yyyy-mm-dd
    is it possible to have them in they typical european format of dd-mm-yyyy in a table?

    thanks for any help.


Comments

  • Registered Users Posts: 68,317 ✭✭✭✭seamus


    Depends on the data type.

    If it's a date, datetime or timestamp, then it's stored in the YYYY-MM-DD format and you can't change that.

    You can reformat it though when you're retrieving it, e.g.

    SELECT DATE_FORMAT('%d-%m-%Y', date_column) FROM TABLE....

    If it's a varchar/char (as I've seen people store dates before :(), then you can do whatever the hell you like.

    All you need to do is reformat it when


  • Registered Users Posts: 3,875 ✭✭✭ShoulderChip


    Ah cool, yeah it is stored as date alright,
    is it possible to combine the date format with a select all statement?


  • Closed Accounts Posts: 18,163 ✭✭✭✭Liam Byrne


    They're stored that way so that you can easily do date calculations - e.g

    2005-10-15 is less than 2009-10-01; the other way around it wouldn't be
    is it possible to combine the date format with a select all statement


    SELECT *, DATE_FORMAT('%d-%m-%Y', date_column) AS formatted_date FROM table....

    date_column will give you the date, for calculations, if required
    formatted_date will give you the date in the format that you're looking for


Advertisement