Change MYSQL date format

后端 未结 4 1949
我寻月下人不归
我寻月下人不归 2021-01-28 10:10

I have a table in MYSQL of which 3 columns have dates and they are formatted in the not desired way.

Currently I have: mm/dd/yyyy and I want to change t

相关标签:
4条回答
  • 2021-01-28 10:16

    try this:

    select date_format(curdate(), '%d/%m/%Y');
    

    In you case you have to use this query.If all three columns are of datetime type

    select date_format(CRTD, '%d/%m/%Y'),
           date_format(INSR, '%d/%m/%Y'),
           date_format(SERD, '%d/%m/%Y')
    From yourTable
    
    0 讨论(0)
  • 2021-01-28 10:20

    You can use the date_format() function to format your dates any way you want.

    If you want to change the format for every date on any database you work with, you should change the value of the date_format system variable.

    0 讨论(0)
  • 2021-01-28 10:25

    UPDATE Vehicles SET yourdatecolumn=DATE_FORMAT(STR_TO_DATE(yourdatecolumn, '%c-%d-%Y'), '%d-%c-%Y')

    0 讨论(0)
  • 2021-01-28 10:34

    Your current datatype for your column is not date right? you need to convert it to date first using STR_TO_DATE() and convert back to string

    SELECT DATE_FORMAT(STR_TO_DATE(colName, '%c/%d/%Y'), '%d/%c/%Y')
    FROM table1
    

    SQLFiddle Demo

    0 讨论(0)
提交回复
热议问题