SQL typed date literals
DATE '2026-01-31' is a date, not a string to be converted. The standard spelling is immune to session language settings, where it is supported at all.
- Kategorie
- Conversion
- Returns
date, timestamp or time- In this category
- 16 of 39
Syntax
DATE 'yyyy-mm-dd'
TIMESTAMP 'yyyy-mm-dd hh:mm:ss'
TIME 'hh:mm:ss'
Each block is a separate form. The support table and the examples show which engine takes which.
Engine-Unterstützung
| Engine | Support | Notizen |
|---|---|---|
| SQL Server | Not built in | no DATE literal; CONVERT or CAST a string, or the ODBC escape { d '2026-01-31' } |
| PostgreSQL | Ja | Supported under this name. |
| MySQL | Ja | Supported under this name. |
| SQLite | Not built in | no typed literals; ISO-8601 text compares correctly by itself |
| Oracle | Ja | DATE and TIMESTAMP literals; Oracle's DATE also holds a time of day |
Beispiele
PostgreSQL
SELECT * FROM orders WHERE order_date >= DATE '2026-01-01';
Oracle
SELECT * FROM orders WHERE order_date >= DATE '2026-01-01';
MySQL
SELECT TIMESTAMP '2026-01-31 10:00:00' AS ts;
Gut zu wissen
- SQL Server rejects DATE '...' (it reads DATE as a column name). Use CAST('2026-01-31' AS date), or the ODBC escape { d '2026-01-31' }, which SQL Server itself parses and which returns datetime.
- The literal is always ISO yyyy-mm-dd regardless of session settings. A bare string is read through NLS_DATE_FORMAT on Oracle and DateStyle on PostgreSQL, and as a datetime it depends on DATEFORMAT on SQL Server.
- On Oracle, DATE '2026-01-31' means midnight, and DATE columns often carry a time. WHERE order_date = DATE '2026-01-31' misses every row stamped after 00:00:00; use a half-open range.
Questions about Date literals
Why prefer DATE '...' over a quoted string?
A bare string is converted using session settings; the typed literal's format is fixed by the standard. The same query then returns the same rows whatever the client's locale.
Does SQLite need the literal?
No. SQLite stores dates as ISO-8601 text (or julian day numbers), so '2026-01-31' compared against a date column is already correct and index-friendly.
Browse every function in the SQL function reference, or see what the SQLly desktop app does for your database.
Related on SQLly
Cheat sheets for the engines that have it: PostgreSQL, MySQL, Oracle.
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.