Skip to content

time

Package timeext adds Go-time-backed scalar functions that go beyond SQLite’s built-in datetime(): duration arithmetic with Go duration syntax, field extraction, truncation, and unix conversions.

time_now() -- current instant, RFC3339 nanos, UTC (non-deterministic)
time_unix(t) -- t as unix seconds (INTEGER)
time_from_unix(secs) -- unix seconds → RFC3339 UTC
time_add(t, dur) -- t + a Go duration ('24h', '-90m', '1h30m')
time_diff(a, b) -- a - b, in seconds (REAL)
time_part(t, field) -- year|month|day|hour|minute|second|nanosecond|weekday|yearday
time_trunc(t, dur) -- round t down to a multiple of dur (since the epoch, UTC)
time_format(t, layout) -- reformat using a Go reference layout

A timestamp argument may be RFC3339(/nano), ‘YYYY-MM-DD HH:MM:SS’, or ‘YYYY-MM-DD’. Any NULL argument yields NULL. The package name is timeext to avoid shadowing the standard library; the SQL functions are the time_* names above.


Full API: pkg.go.dev/gosqlite.org/ext/time