// dates & times reference

SQL date plus integer arithmetic

In Oracle and PostgreSQL, date + integer adds exactly that many days; the other engines reject or misread it.

Categoria
Dates & times
Returns
date / timestamp
In this category
76 of 121

Sintaxe

date + n
date - n
date + n/24

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

Suporte a mecanismos

MotorSupportNotas
SQL Server Different name or syntax datetime + 7 adds days; date + 7 is an error; use DATEADD(DAY, n, d)
PostgreSQL Sim Supported under this name.
MySQL Not built in '2026-01-01' + 5 is numeric addition, use DATE_ADD
SQLite Not built in needs modifiers: date(d, '+5 days')
Oracle Sim Supported under this name.

Exemplos

Oracle

SELECT SYSDATE + 7 FROM dual;  -- one week out

PostgreSQL

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

Oracle

SELECT SYSDATE + 3/24 FROM dual;  -- three hours out

Bom saber

  • MySQL is the trap: '2026-08-01' + 7 converts the string to the number 2026 and returns 2033, and DATE '2026-08-01' + 7 returns the number 20260808. Use DATE_ADD or + INTERVAL 7 DAY there.
  • Fractions scale by day in Oracle: d + 1/24 is one hour later, d + 7/1440 is seven minutes. PostgreSQL needs intervals for that: d + INTERVAL '7 minutes'.
  • PostgreSQL's date + int returns a date; timestamp + int is rejected; cast or use intervals to avoid confusion.

Questions about DATE + N

Is date + 7 portable?

No. It is right on Oracle and PostgreSQL, a type error on SQL Server date columns (datetime accepts it), and a silent numeric add in MySQL and SQLite. Portable code spells out DATEADD, INTERVAL or modifiers per engine.

How do I add hours on PostgreSQL?

Not with an integer: ts + INTERVAL '3 hours'. date + int is days-only.

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