SQLite 3 reference · Date and Time Functions
SQLite DATETIME() Function
Return a date and time as text in YYYY-MM-DD HH:MM:SS form, optionally shifted with modifiers.
SQLite 3
Syntax
datetime(time-value, modifier, ...)
Parameters
| Parameter | Description |
|---|---|
time-value |
A date/time: 'YYYY-MM-DD', 'YYYY-MM-DD HH:MM:SS', 'now', a Julian day number, or a Unix time with the 'unixepoch' modifier. |
modifiers optional |
Adjustments applied left to right, such as '+1 day', '-3 months', 'start of month', 'weekday 1', 'localtime', 'unixepoch'. |
Return value
Text YYYY-MM-DD HH:MM:SS, or NULL.
Examples
SELECT datetime('2026-01-05') AS midnight,
datetime('2026-01-05 22:00', '+3 hours') AS plus_3h;
Output
midnight | plus_3h 2026-01-05 00:00:00 | 2026-01-06 01:00:00
SELECT datetime(1767225600, 'unixepoch') AS from_unix,
datetime('now') > '2020-01-01' AS now_is_later;
Output
from_unix | now_is_later 2026-01-01 00:00:00 | 1
In other languages
NOW()· PostgreSQLTO_TIMESTAMP()· PostgreSQL
Related
DATE()· Return a date as text in YYYY-MM-DD form, optionally shifted with modifiers like '+7 days' or 'start of month'.TIME()· Return the time part of a date/time as text in HH:MM:SS form, optionally shifted with modifiers.UNIXEPOCH()· Return a date/time as a Unix timestamp: whole seconds since 1970-01-01 00:00:00 UTC.STRFTIME()· Format a date/time with % codes, such as %Y year, %m month, %d day, %H hour, %W week and %w weekday.- SQL Date Functions · tutorial