SQL 如何在sqlite中为dateTime添加时间?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21309204/
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
How to add time to a dateTime in sqlite?
提问by Let me see
I have a table and in the table there is a date creationDate. which stores the timestamp like this
我有一张桌子,桌子上有一个日期creationDate。像这样存储时间戳
2013-12-23 10:07:42
2013-12-23 10:14:11
Actually I was using the mysql2sqlite.sh script to convert the database from mysql to sqlite. and while converting database it reduced the time 5:30 from the creationDate column. It might be some GMTproblem.
So now I want to update the timestamp and add 5 hours 30 minutes to each entry in the creationDate column.
I searched about it a lot but i didnt find the solution.
So how can i do it in sqlite ?
实际上,我使用 mysql2sqlite.sh 脚本将数据库从 mysql 转换为 sqlite。在转换数据库时,它从 creationDate 列中减少了 5:30 的时间。这可能是一些GMT问题。
所以现在我想更新时间戳并向 creationDate 列中的每个条目添加 5 小时 30 分钟。
我搜索了很多,但我没有找到解决方案。那么我怎样才能在 sqlite 中做到这一点呢?
回答by laalto
You can use the sqlite date functionsfor simple math like this:
您可以使用sqlite 日期函数进行简单的数学运算,如下所示:
UPDATE tablename SET creationDate=DATETIME(creationDate, '+330 minutes');
Though usually it makes more sense to keep the database data in UTC and format to local timezone when displaying it.
尽管通常将数据库数据保持在 UTC 格式并在显示时将其格式设置为本地时区更有意义。