user410932
user410932

Reputation: 3015

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)

Upvotes: 0

Views: 1365

Answers (1)

Serhii Mamontov
Serhii Mamontov

Reputation: 4932

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

Upvotes: 1

Related Questions