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

Create a free account to save this page, take notes and track your progress. Sign in

Syntax

datetime(time-value, modifier, ...)

Parameters

ParameterDescription
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

Dates and timesTry it yourself
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
From Unix time, and nowTry it yourself
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

Was this page helpful?