Sanyin
Sanyin

Reputation: 101

How to calculate time difference in SQLite and SUM these values, grouping by day?

I want to calculate total difference between two date fields in SQLite (they are declared as REAL). I.E. datefield1 and datefield2 and group by day.

Datefield1 is login date, datefield2 is logout date. Each day, user can login/logout several times. I want to sum up login time of a user (datefield2-datefield1) for each day.

Upvotes: 1

Views: 1210

Answers (1)

Sanyin
Sanyin

Reputation: 101

SOLVED:

Query

select id, datetime(logindate), datetime(logoutdate), 
sum((julianday(logoutdate) - julianday(logindate)))
from MyTable GROUP BY strftime('%d', logindate);

Upvotes: 1

Related Questions