sqlite添加日期到日期 [英] sqlite adding days to a date

查看:121
本文介绍了sqlite添加日期到日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试编写一个sqlite语句,该语句从表中返回一个日期,并从另一列中添加了一定天数。日期存储为 YYYY-MM-DD HH:mm:ss ,将天数存储为整数。

I'm trying to write an sqlite statement which returns a date from the table with a certain number of days added from another column. The date is stored as YYYY-MM-DD HH:mm:ss and the number of days just as an integer.

我有

SELECT strftime('%Y-%m-%d %H:%M:%S' , 
strftime('%s',transactions.date)+repeattransactions.interval*24*60*60) 
FROM transactions,repeattransactions

但这给年份和各种各样的事物增加了更多的数字。想知道我是否可以得到一些帮助,添加日期并以相同的格式输出?

but this is adding wierd amounts to the years and all sorts. Wonder if I could get some help adding the days and outputting it in the same format?

谢谢。

推荐答案

$ sqlite3
SQLite version 3.7.7 2011-06-23 19:49:22
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite> create table t (tdate, tinterval);
sqlite> insert into t values ('2011-09-08 11:11:11', 5);
sqlite> select datetime(t.tdate,'+'||t.tinterval||' days') from t;
2011-09-13 11:11:11

请参见 SQLite3日期&时间函数

这篇关于sqlite添加日期到日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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