日期类型更新和数据更新到mysql中的特定格式

时间:2022-09-26 09:51:49

In my table I've data in date field as 5/1/2012, it is of type varchar

在我的表中,我将日期字段中的数据作为5/1/2012,它的类型为varchar

I need to alter the column as date and update the date as 2012-05-01

我需要将列更改为日期并将日期更新为2012-05-01

Any idea?

2 个解决方案

#1


0  

Inorder to modify the table column_type perform:

为了修改表column_type执行:

ALTER TABLE table_name MODIFY COLUMN column_name date

ALTER TABLE table_name MODIFY COLUMN column_name date

But note that Invalid DATE, DATETIME, or TIMESTAMP values are converted to the “zero” value of the appropriate type

但请注意,无效的DATE,DATETIME或TIMESTAMP值将转换为相应类型的“零”值

So if 5/1/2012 is the input value already in the table, it will be converted to 0000-00-00

因此,如果5/1/2012是表中已有的输入值,则将其转换为0000-00-00

Please refer http://dev.mysql.com/doc/refman/5.1/en/datetime.html for details

有关详细信息,请参阅http://dev.mysql.com/doc/refman/5.1/en/datetime.html

#2


0  

 STR_TO_DATE(datestring, '%Y-%d-%m')

try this in your query....

在你的查询中尝试这个....

#1


0  

Inorder to modify the table column_type perform:

为了修改表column_type执行:

ALTER TABLE table_name MODIFY COLUMN column_name date

ALTER TABLE table_name MODIFY COLUMN column_name date

But note that Invalid DATE, DATETIME, or TIMESTAMP values are converted to the “zero” value of the appropriate type

但请注意,无效的DATE,DATETIME或TIMESTAMP值将转换为相应类型的“零”值

So if 5/1/2012 is the input value already in the table, it will be converted to 0000-00-00

因此,如果5/1/2012是表中已有的输入值,则将其转换为0000-00-00

Please refer http://dev.mysql.com/doc/refman/5.1/en/datetime.html for details

有关详细信息,请参阅http://dev.mysql.com/doc/refman/5.1/en/datetime.html

#2


0  

 STR_TO_DATE(datestring, '%Y-%d-%m')

try this in your query....

在你的查询中尝试这个....