在mysql日期更改年份 [英] Changing year in mysql date
本文介绍了在mysql日期更改年份的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
无论原始日期如何,我如何将一年隐蔽到2013年。
所以如果一个日期是2009-01-01它将是2013-01-01,但如果是2012-01-04,它会转换到2013- 01-14。
我认为这很简单明了,但是我无法想象出来,/ / / / p>
解决方案
很简单:
DATETIME:
UPDATE table_name
SET date_col = DATE_FORMAT(date_col,'2013-%m-%d%T');
DATE:
UPDATE table_name
SET date_col = DATE_FORMAT(date_col,'2013-%m-%d');
I have a bunch of dates in our database stored in the standard mysql date type.
How can I covert a year to 2013, regardless of original date.
So if a date is 2009-01-01 it would be 2013-01-01, but if it's 2012-01-04, it'd convert to 2013-01-14.
I figured it'd be simple and obvious, but I couldn't figure it out =/
解决方案
That's simple:
for DATETIME:
UPDATE table_name
SET date_col=DATE_FORMAT(date_col,'2013-%m-%d %T');
for DATE:
UPDATE table_name
SET date_col=DATE_FORMAT(date_col,'2013-%m-%d');
这篇关于在mysql日期更改年份的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文