UNIXEPOCH
Returns a time value as the number of seconds since 1970-01-01 00:00:00 UTC (a Unix timestamp), after applying any modifiers.
See also:
[SELECT] [DATETIME] [TIMEDIFF]
Syntax
SELECT UNIXEPOCH(time_value [, modifier ...]) FROM <multipartIdentifier>;
Arguments
time_value
A time value in any format the date and time functions accept, such as 2024-01-01 00:00:00, an ISO 8601 timestamp like 2024-01-01T00:00:00Z, or now.
modifier
Optional date modifiers such as +1 day or -365 days. The subsec modifier keeps fractional seconds.
Return Value(s)
Returns an integer, or a floating point number with subsec. The result is NULL for an invalid time value.
Examples
Convert time values
The first two values are the same instant in two formats; the third adds a day:
SELECT UNIXEPOCH('2024-01-01 00:00:00') AS a,
UNIXEPOCH('2024-01-01T00:00:00Z') AS b,
UNIXEPOCH('2024-01-01', '+1 day') AS c;
|------------|------------|------------|
| a | b | c |
|------------|------------|------------|
| 1704067200 | 1704067200 | 1704153600 |
|------------|------------|------------|
Filter rows by age
The following query returns the repositories in a GitHub organization that received a push in the last year:
SELECT name
FROM github.repos.repos
WHERE org = 'stackql-labs'
AND UNIXEPOCH(pushed_at) > UNIXEPOCH('now', '-365 days');
For more information, see https://www.sqlite.org/lang_datefunc.html