// dates & times reference

SQL SQLite date modifiers

Returns a modified time value: each modifier is a text argument applied left to right inside date(), time(), datetime() or strftime().

Kategorie
Dates & times
Returns
text
In this category
63 of 121

Syntax

datetime('now', 'localtime')
datetime(ts, 'unixepoch')
date(d, 'start of month', '+1 month', '-1 day')

Each block is a separate form. The support table and the examples show which engine takes which.

Engine-Unterstützung

EngineSupportNotizen
SQL Server Not built in DATEADD and DATEFROMPARTS apply the shifts
PostgreSQL Different name or syntax interval arithmetic and date_trunc
MySQL Different name or syntax DATE_ADD with units
SQLite Ja Supported under this name.
Oracle Different name or syntax date arithmetic and TRUNC

Beispiele

SQLite

SELECT date('now', 'start of month', '+1 month', '-1 day') AS month_end;

SQLite

SELECT datetime(1700000000, 'unixepoch', 'localtime') AS created;

SQLite

SELECT date(created_at, '+7 days') AS follow_up FROM orders;

Gut zu wissen

  • Order matters: date('2024-01-31', '+1 month', 'start of month') and the reversed order land on different days; each step applies to the intermediate result.
  • 'unixepoch' must come first, right after the value: datetime(1700000000, 'unixepoch', '+1 day') is valid; a later position misreads the number.
  • 'localtime' uses the host machine's zone, so results move with the machine; servers running UTC make 'localtime' a no-op.

Questions about date modifiers

How do I get the last day of the month in SQLite?

date(d, 'start of month', '+1 month', '-1 day'): jump to the first, forward a month, back a day. SQLite has no EOMONTH-style function.

Why must 'unixepoch' come first?

It tells SQLite how to interpret the bare number; later modifiers then shift the decoded value. Putting 'localtime' first makes the number meaningless.

Browse every function in the SQL function reference, or see what the SQLly desktop app does for your database.

Cheat sheets for the engines that have it: PostgreSQL, MySQL, SQLite, Oracle.

// fewer lookups

Functions your engine actually has

SQLly's completion lists the built-in functions of the engine you're connected to, whether that's SQL Server, PostgreSQL, MySQL, SQLite or Oracle. Hover a function for help, and signature hints show each argument as you type.