sqlite 将 x 天添加到日期(x 存储在 table 中)

sqlite add x days to date (x stored in table)

我需要在 sqlite(c# 应用程序)中做这样的事情:

select DATE(XDATE,'+XDAYS day') from TABLE

XDATE和XDAYS字段为字符串类型,存储在"TABLE"table.

有人理解我并能帮助我吗?谢谢。

使用 Sqlite 日期时间修饰符 (https://www.sqlite.org/lang_datefunc.html)

date(timestring, modifier, modifier, ...)

The time string can be followed by zero or more modifiers that alter date and/or time. Each modifier is a transformation that is applied to the time value to its left. Modifiers are applied from left to right; order is important. The available modifiers are as follows.

NNN days

NNN hours

NNN minutes

NNN.NNNN seconds

NNN months

NNN years

start of month start of year start of day weekday N unixepoch

localtime utc

例如: SELECT date('now','start of month','+1月','-1天');

CREATE TABLE [theDates] (
  [d] VARCHAR(100)  NULL,
  [diff] varchar(100)  NULL
)


insert into [TheDates] VALUES ('now', '-10 day')   

Select d, diff, date([d], [diff]) from [TheDates]


d             diff        date([d], [diff])
-------------------------------------------
now           -10 day     2015-06-02

如果你有数字数据

insert into [TheDates] VALUES ('now', -10)   

Select d, diff, date([d], ([diff] || ' day')) from [TheDates]


d             diff        date([d], ([diff] || ' day'))
-------------------------------------------------------
now           -10 day     2015-06-02