SQLite Date Time Functions
SQLite has no dedicated date or time storage type. Store date/time values as ISO-8601 text, Julian day numbers, or Unix timestamps; the date and time functions accept ISO-8601 text and Julian day numbers directly. For Unix seconds, add the 'unixepoch' modifier, for example datetime(1748528160, 'unixepoch').
To format a date in SQLite, use strftime() with format codes such as %Y-%m-%d for a calendar date or %Y-%m-%d %H:%M:%S for a timestamp. Supported codes vary by SQLite version; an unsupported code makes strftime() return NULL. See SQLite strftime() format codes.
Choose a function by task:
- Return a date, time, or combined date and time with
date(),time(), ordatetime(). - Format values with
strftime(), including year, month, day, ISO week, and Unix timestamp output. - Get a human-readable calendar interval with
timediff(). - Calculate numeric elapsed-time differences with
julianday()(days) orunixepoch()(seconds).
For precise Unix timestamp conversion, prefer the explicit 'unixepoch' modifier over 'auto' when you know the input format. 'auto' can misread Unix timestamps from the first 63 days of 1970 as Julian day numbers. Date/time modifiers are applied from left to right, so their order can change the result.
-
date
The SQLitedate()function converts a time value specified by a time value and modifiers to a date string inYYYY-MM-DDformat. -
datetime
The SQLitedatetime()function converts a time value specified by a time value and modifiers to a datetime string inYYYY-MM-DD HH:MM:SSformat. -
julianday
Use SQLite julianday() to convert time-values into fractional day counts, calculate elapsed days, and apply date modifiers. -
strftime
Format SQLite date and time values with strftime() codes for calendar dates, ISO weeks, fractional seconds, Julian days, and Unix timestamps. -
time
The SQLitetime()function converts a time value specified by a time value and modifiers to a time string inHH:MM:SSformat. -
timediff
Learn how SQLite timediff() returns a calendar-aware modifier and when to use julianday() or unixepoch() for exact elapsed time. -
unixepoch
Use SQLite unixepoch() to convert time-values to Unix seconds, calculate elapsed time, and preserve fractional seconds with subsec.