// dates & times reference

ANSI SQL DATE literal

DATE 'YYYY-MM-DD' builds a date constant without TO_DATE, CAST or implicit string parsing ambiguity.

Categoria
Dates & times
Returns
date
In this category
83 of 121

Sintaxe

DATE 'YYYY-MM-DD'

Suporte a mecanismos

MotorSupportNotas
SQL Server Different name or syntax no typed literal; { d '2026-08-01' } or CAST('2026-08-01' AS date)
PostgreSQL Sim Supported under this name.
MySQL Sim Supported under this name.
SQLite Not built in no typed literals; date('2026-08-01')
Oracle Sim Supported under this name.

Exemplos

PostgreSQL

SELECT * FROM orders WHERE ordered_on >= DATE '2026-08-01';

Oracle

SELECT * FROM orders WHERE ordered_on >= DATE '2026-08-01';

MySQL

SELECT DATE '2026-08-01' + INTERVAL 7 DAY;

Bom saber

  • Write the text as year-month-day. All three accept DATE '2026-8-1' without padding. MySQL and Oracle reject anything else, including '08/01/2026' and a time part (DATE '2026-08-01 10:00' raises error 1525 and ORA-01861). PostgreSQL reads '08/01/2026' by its DateStyle and silently drops a time part.
  • Time zones never enter it: it is a bare date. TIMESTAMP '2026-08-01 12:00:00' is the parallel form for datetimes, with engine-specific zone rules.
  • SQLite has no typed literals: SELECT DATE '2026-08-01' fails with 'no such column: DATE'. Use date('2026-08-01') or the bare ISO string.

Questions about DATE literal

Why prefer DATE '2026-08-01' over a bare string?

Session settings cannot reinterpret it. On Oracle a bare '2026-08-01' is parsed with NLS_DATE_FORMAT and fails under the default DD-MON-RR mask; DATE '2026-08-01' always means August 1. PostgreSQL reads ISO strings the same way under every DateStyle, so there the literal mostly documents the type.

Does SQL Server support it?

No. SELECT DATE '2026-08-01' fails with 'Invalid column name DATE'. Use the ODBC escape { d '2026-08-01' } or CAST('2026-08-01' AS date).

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: SQL Server, PostgreSQL, MySQL, 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.