如何在MySQL数据库中的所有时间戳/ DATETIME中添加偏移量? [英] How to add an offset to all timestamps/DATETIME in a MySQL database?
本文介绍了如何在MySQL数据库中的所有时间戳/ DATETIME中添加偏移量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果系统时间当数据最初写入数据库时是错误的。
或者,就像我的情况
来创建最近的DEMO数据用于历史数据中的应用程序。
- 有没有办法一次转移数据库中的所有DATETIME字段? / li>
- 如果没有,一个表中所有条目的DATATIME列如何移位(即添加一些偏移量)?
感谢您的答案!
解决方案
UPDATE表SET date_column = DATE_ADD(date_column,INTERVAL 1 YEAR);
这应该是诀窍。
I have some MySQL databases that have several tables that contain (amongst others) some DATETIME columns. I am searching for a way to add some amount of time (say one year) to all DATETIME columns in the whole database.
This can be useful if the system-time was wrong when the data was originally written to the database.
OR, as in my case
to create recent DEMO-data for an application out of historical data.
- Is there a way to shift all DATETIME fields in a Database at once?
- If not, How can the DATATIME column of all entries in ONE table be shifted (i.e. add some offset)?
thanks for your answers!
解决方案
UPDATE table SET date_column = DATE_ADD(date_column, INTERVAL 1 YEAR);
This should do the trick.
这篇关于如何在MySQL数据库中的所有时间戳/ DATETIME中添加偏移量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文