我需要在 sqlite (c# 应用程序)中执行类似的操作:
select DATE(XDATE,'+XDAYS day') from TABLE
XDATE和XDAYS字段是字符串类型,存储在“TABLE”表中。
有人理解我并可以帮助我吗?谢谢。
最佳答案
使用 SqlLite DateTime 修饰符 ( 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('现在','月初','+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
关于c# - sqlite 添加 x 天至今(x 存储在表中),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30803525/