如何在sqlite中添加dateTime的时间? [英] How to add time to a dateTime in sqlite?

查看:593
本文介绍了如何在sqlite中添加dateTime的时间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一张表,表中有一个日期 creationDate 。它存储这样的时间戳

I have a table and in the table there is a date creationDate. which stores the timestamp like this

2013-12-23 10:07:42
2013-12-23 10:14:11

其实我正在使用mysql2sqlite.sh脚本将数据库从mysql转换为sqlite 。而在转换数据库时,它从creationDate列减少了时间5:30。这可能是一些 GMT 问题。


所以现在我想更新时间戳,并在creationDate列中的每个条目添加5小时30分钟。

我搜索了很多,但是我没有找到解。
那么我如何在sqlite中执行?

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 GMT problem.

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 ?

推荐答案

你可以使用 sqlite date函数,用于简单的数学运算,如下所示:

You can use the sqlite date functions for simple math like this:

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.

这篇关于如何在sqlite中添加dateTime的时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆