更改 mySql 数据库表中的日期格式

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20046978/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 19:27:42  来源:igfitidea点击:

Change date format in mySql database table

mysqlsqldate

提问by user2815059

Morning everyone. Just a quick question. In my existing MySql database I've few columns with dates in it. Currently these are yyyy-mm-ddformat but now I need to change it all to dd-mm-yyyyformat. I've tried select date_format(curdate(), '%d/%m/%Y');but it doesnt update existing data in my table.Is there any easy way of doing it? Or even if its not easy could you give me some suggestion how to do it please and thank you.

大家早上好。只是一个简单的问题。在我现有的 MySql 数据库中,我有几个带有日期的列。目前这些是yyyy-mm-dd格式,但现在我需要将其全部更改为dd-mm-yyyy格式。我试过了,select date_format(curdate(), '%d/%m/%Y');但它没有更新我表中的现有数据。有什么简单的方法吗?或者即使这并不容易,您能否给我一些建议如何去做,谢谢。

回答by vhadalgi

Try using

Try using

SELECT DATE_FORMAT(dateColumn,'%d/%m/%Y') AS dateColumn FROM table

回答by Krish R

You cann't able to change the default dateformat in table. Default DATEformat is 'YYYY-MM-DD'. But you can able to retrive the datecolumn value as your way.

您无法更改date表格中的默认格式。默认DATE格式为“YYYY-MM-DD”。但是您可以date按照自己的方式检索列值。

Ref: http://dev.mysql.com/doc/refman/5.1/en/datetime.html

参考:http: //dev.mysql.com/doc/refman/5.1/en/datetime.html