sqlite3 函数嵌套疑问

2018-02-22 17:25:14 +08:00
 andmspy

请教一下,想每次批量处理提取的数据都是当前日期的数据,可以就是不能提取出来,也没有报错,就是不知道为什么

select date from worker where date=(select date('now'))

背景: 表:worker 字段:date 格式:2018/2/22

但是如果修改成 select date from worker where date=‘ 2018/2/22 ’ 这样就可以成功提取出来,用函数就不行了。

1039 次点击
所在节点    数据库
4 条回复
Dic4000
2018-02-22 18:16:54 +08:00
试试:select date from worker where date=Date('now')
alpenstock
2018-02-23 09:48:58 +08:00
sqlite date() 函数默认的格式是 2018-02-22,不是 2018/2/22
可以用
select date from worker where date=(select strftime('%Y/%m/%d','now'));
或者
select date from worker where date= strftime('%Y/%m/%d','now');
alpenstock
2018-02-23 09:52:31 +08:00
SQLite does not have a storage class set aside for storing dates and/or times. Instead, the built-in Date And Time Functions of SQLite are capable of storing dates and times as TEXT, REAL, or INTEGER values:

TEXT as ISO8601 strings ("YYYY-MM-DD HH:MM:SS.SSS").
REAL as Julian day numbers, the number of days since noon in Greenwich on November 24, 4714 B.C. according to the proleptic Gregorian calendar.
INTEGER as Unix Time, the number of seconds since 1970-01-01 00:00:00 UTC.

参考自 http://sqlite.org/datatype3.html
andmspy
2018-03-06 23:19:15 +08:00
谢谢,谢谢。

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/431706

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX