The five date functions and their modifiers
SQLite has five date/time functions, all of which accept the same set of modifiers for arithmetic. Memorize the modifiers; the functions are easy.
date(time, modifiers...)— returns YYYY-MM-DD.time(time, modifiers...)— returns HH:MM:SS.datetime(time, modifiers...)— returns YYYY-MM-DD HH:MM:SS.julianday(time, modifiers...)— Julian day as REAL.strftime(format, time, modifiers...)— custom format string.unixepoch(time, modifiers...)(3.38+) — seconds since 1970.
Useful modifiers:
'+N days','-N hours','+N minutes', etc.'start of month','start of year','start of day'.'weekday N'where 0=Sunday, 6=Saturday — moves forward to the next weekday N.'localtime','utc'— timezone shift.
Tip:
datetime('now') always returns UTC. If you store local time, store the offset too or convert to UTC at write time. Mixed-timezone columns are a permanent source of bugs.