سؤال

I have a table which have entries like this.

SELECT entrydate FROM entities;

2013-04-29 13:24:34
2013-04-29 13:24:46
2013-04-29 13:27:19

What I want to do is that taking difference between current date and these entities. I try

SELECT strftime('%s','now') - strftime('%s', entrydate) FROM entities;
-7881
-7893
-8046

It returns negative values although current timestamp should be bigger than entities.

I compared strftime('%s','now') and date +%s outputs and saw they are same.

I figured out that strftime('%s', entrydate) returns bigger value than it should be. How can I fix this issue? Thanks

هل كانت مفيدة؟

المحلول

I fixed it by putting 'localtime' modifier while getting current time.

SELECT strftime('%s','now', 'localtime') - strftime('%s', entrydate) FROM entities;
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top