Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

mySql Changing date format for table

  • 10-02-2009 11:12AM
    #1
    Registered Users, Registered Users 2 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, Registered Users 2 Posts: 68,173 ✭✭✭✭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, Registered Users 2 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