SQLite Forum

How can I calc weekly totals?
Login
The constant 1721061.5 is the JulianDay of '0000-01-03' which is the first Monday in the "round trippable" dates supported by the SQLite3 datetime functions.

`cast(julianday(datecolumn)-1721061.5 as integer)/7` gives us the Week Number (as an integer) based on a week starting on a Monday (base 0).

You then multiple this by 7 to convert back to days, and add 1721067.5 (which is the JulianDay value corresponding to '0000-01-09'), which is the JulianDay value on which the first week ends, and convert the result back to a Gregorian date.

Thus given any Gregorian date in the Common Era you can now compute the Week Ending date, for a week spanning Monday -> Sunday.  You could (for example) return the "starting date" of each week by changing the last constant to 1721061.5.