// dates & times reference

SQL SQLite datetime modifiers

Modifiers are extra string arguments to date(), datetime() and strftime(), applied left to right to shift and truncate the value.

类别
Dates & times
Returns
text (formatted timestamp)
In this category
79 of 121

语法

datetime(t, modifier1, modifier2, ...)

引擎支持

引擎Support备注
SQL Server Not built in No built-in equivalent.
PostgreSQL Not built in No built-in equivalent.
MySQL Not built in No built-in equivalent.
SQLite 是 Supported under this name.
Oracle Not built in No built-in equivalent.

示例

SQLite

SELECT date('2026-08-01', 'start of month');  -- 2026-08-01

SQLite

SELECT date('2026-08-01', 'start of month', '-1 day');  -- 2026-07-31

SQLite

SELECT datetime('2026-08-01 10:00', '+7 days', 'weekday 1');  -- 2026-08-10 10:00:00

值得了解

  • Modifiers apply in order: date(d, 'start of month', '+1 month', '-1 day') is the month's last day; reordering changes the result.
  • 'start of month' zeroes the time too. 'weekday N' (0 = Sunday ... 6 = Saturday) moves forward to the next date with that weekday and leaves the date alone if it already matches: date('2026-08-02', 'weekday 0') stays 2026-08-02.
  • 'localtime' and 'utc' convert using the OS time zone; inside SQLite there is no per-session zone, so results shift with the machine's clock settings.

Questions about datetime() modifiers

How do I truncate to the month in SQLite?

date(d, 'start of month'). For the year use 'start of year'; there is no quarter modifier; derive it with month arithmetic.

Can modifiers add months across month ends?

Not by default: date('2026-01-31', '+1 month') builds 2026-02-31 and normalizes it to 2026-03-03. SQLite 3.46 added the 'floor' modifier for this: date('2026-01-31', '+1 month', 'floor') is 2026-02-28.

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: SQLite.

// 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.