简体   繁体   中英

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).

I couldn't find a function to calculate "age()" in SQLite (like they have in 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)

You are able to retrieve difference between current time and "last_updated" only by SQL language:

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 . Instead of 2011-08-18 22:49:00 you can pass last_updated column name and it should return you difference between them.

You can read more here

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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