tags:

views:

833

answers:

2

How do I get the difference in days between 2 dates in SQLite? I have already tried something like this:

SELECT Date('now') - DateCreated FROM Payment

It returns 0 every time.

+3  A: 
 SELECT (julianday(Date('now')) - julianday(DateCreated)) FROM Payment;
Fred
+2  A: 

The SQLite wiki is a great reference and the DateAndTimeFunctions page is a good one to bookmark. It's also helpful to remember that it's pretty easy to play with queries with the sqlite command line utility:

sqlite> select julianday(datetime('now'));
2454788.09219907
sqlite> select datetime(julianday(datetime('now')));
2008-11-17 14:13:55
converter42