如何获取两个 Unix 时间戳之间的行
在我的 SQLite DB 中,我有一个 created_date
作为毫秒时间戳,例如 1646384581034
。
因此,如果存在这种格式的值 2022-03-03 00:00:00
或 2022-03-03T00:00:00
,我如何获取例如之间的行该日期和当前日期?
WHERE
created_date BETWEEN
strftime('%s', '2022-03-03 00:00:00') * 1000
AND
Current_timstamp
这是我的要求,语法可能不正确。
In my SQLite DB I have a created_date
as millisecond timestamps, e.g. 1646384581034
.
So if there are values in this format 2022-03-03 00:00:00
or 2022-03-03T00:00:00
, how can I fetch rows between e.g. this date and the current date?
WHERE
created_date BETWEEN
strftime('%s', '2022-03-03 00:00:00') * 1000
AND
Current_timstamp
This is my requirement, the syntax may be incorrect.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以将
2022-03-03 00:00:00
或2022-03-03T00:00:00
等日期时间转换为 unix 纪元时间戳,如以下值中的值列created_date
与函数strftime()
。例如:
或:
列
created_date
包含毫秒,这就是为什么需要乘以 1000。You can convert a datetime like
2022-03-03 00:00:00
or2022-03-03T00:00:00
to a unix epoch timestamp like the values in the columncreated_date
with the functionstrftime()
.For example something like:
or:
The column
created_date
contains miliseconds and this is why the multiplication by 1000 is needed.如果日期是时间戳,您需要这样做(以下两个日期是示例):
或者您可以这样做,我相信:
或者,因为它是一个文本字段:
IF date is a timestamp, you'll need to do like(the following two dates are examples):
Or you can do, I believe:
Or, since it is a text field: