开发者

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 (wor开发者_StackOverflow中文版ks 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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜