Change MYSQL date format

我只是一个虾纸丫 提交于 2019-12-20 07:37:39

问题


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 those dates into dd/mm/yyyy.

Table name is Vehicles and the columns names are:

CRTD
INSR
SERD

回答1:


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




回答2:


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



回答3:


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.




回答4:


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



来源:https://stackoverflow.com/questions/12927684/change-mysql-date-format

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!