简体   繁体   English

检查SQLite记录是否早于特定时间

[英]Check if a SQLite record is older than certain time

I have records in my SQLite database and I'd like to check if a certain record is older than a certain amount of hours (or minutes or seconds). 我在SQLite数据库中有记录,我想检查某个记录是否早于某个小时(或几分钟或几秒钟)。

I couldn't find a function to calculate "age()" in SQLite (like they have in Postgres). 我在SQLite中找不到计算“ age()”的函数(就像它们在Postgres中一样)。 Does it exist? 是否存在?

If not, I was already trying to extract the epoch of the record (works fine) and was thinking to compare that with the epoch of the current time. 如果不是,我已经在尝试提取记录的纪元(工作正常),并正在考虑将其与当前时间的纪元进行比较。 But I can't find a function that will simply return me the epoch of the current timestamp. 但是我找不到一个可以简单地返回当前时间戳记的函数。 Can anybody help? 有人可以帮忙吗?

(Note: I did check SimpleDateFormat, currenttimemillis() etc, but didn't seem to do what I want or I'm missing something) (注意:我确实检查了SimpleDateFormat,currenttimemillis()等,但似乎没有执行我想要的操作,或者我缺少了一些东西)

You are able to retrieve difference between current time and "last_updated" only by SQL language: 您只能通过SQL语言检索当前时间与“ last_updated”之间的时差:

SELECT strftime('%s','now','localtime')-strftime('%s','2011-08-18 22:49:00') as date;

This SQL statement will return me difference between current time and 2011-08-18 22:49:00 . 该SQL语句将向我返回当前时间与2011-08-18 22:49:00之间的2011-08-18 22:49:00 Instead of 2011-08-18 22:49:00 you can pass last_updated column name and it should return you difference between them. 您可以传递last_updated列名,而不是2011-08-18 22:49:00 ,它应返回它们之间的区别。

You can read more here 你可以在这里阅读更多

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM