c# - sqlite 添加 x 天至今(x 存储在表中)

标签 c# sqlite date addition days

我需要在 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/

相关文章:

sql - 更改 PostgreSQL 查询结果的日期格式

c# - 在调用它之前检查是否可以从 api 调用方法

c# - Lambda 表达式选择字段并将其合并为单个字符串

c# - 文本冒险中的编码交互

c# - 仅在 C# 中的特定时间触发事件

android - 如何一次性向sqlite数据库中插入数据

ios - Objective-c 从 sqlite 读取图像

android - sqlite根据计数合并列数据

javascript - 1901 年之前的任何年份的 Angular 最短日期验证不正确

java - ORA-01861 : literal does not match format string error isn't always shown in similar cases