Minus on two strings turns each one into the number at its start, 2026. So every difference within a year is 0. No error, just a wrong answer.
julianday() returns a day number, with a fraction for the time of day. The SQLite docs recommend exactly this for a precise difference: subtract two julianday() or unixepoch() calls.
A plain date ends in .5 because Julian days start at noon. The halves cancel when you subtract.
With times of day, the difference has a fraction. CAST(... AS INTEGER) truncates toward zero, so 6.375 days is 6 whole days.
date(d, '-6 days') does calendar arithmetic and returns text. Use it to write down where a 7-day window starts.
In the editor, write SPAN_DAYS: each user's days from their first order to their last.
Pick an answer above to see the rest
Instructions
1
Write SPAN_DAYS: one row per user with user_id and span, the whole days from their first order to their last. Order by user_id.