// dates & times reference

SQL DATEADD function

Shifts a date or timestamp by an interval. SQL Server and MySQL have a function with unit names; PostgreSQL, SQLite and Oracle add intervals or modifiers instead.

Catégorie
Dates & times
Returns
date / timestamp
In this category
3 of 121

Syntaxe

DATEADD(month, 1, d)  -- SQL Server
DATE_ADD(d, INTERVAL 1 MONTH)  -- MySQL
d + INTERVAL '1 month'

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

Prise en charge des moteurs

MoteurSupportNotes
SQL Server Oui Supported under this name.
PostgreSQL Different name or syntax no DATEADD; date + interval '1 month'
MySQL Oui Supported under this name.
SQLite Different name or syntax no DATEADD; modifiers such as date(d, '+1 month')
Oracle Different name or syntax date + n adds days; ADD_MONTHS for months; INTERVAL literals for the rest

Exemples

SQL Server

SELECT DATEADD(day, 30, order_date) AS due_date
FROM orders;

MySQL

SELECT DATE_ADD(order_date, INTERVAL 30 DAY) AS due_date FROM orders;

PostgreSQL

SELECT order_date + INTERVAL '30 days' AS due_date FROM orders;

SQLite

SELECT date(order_date, '+30 days') AS due_date FROM orders;

Oracle

SELECT order_date + 30 AS due_date,
       ADD_MONTHS(order_date, 1) AS next_month
FROM orders;

Bon à savoir

  • Adding one month to January 31: SQL Server, MySQL and PostgreSQL clamp to February 28 (29 in a leap year). SQLite normalizes the impossible February 31 to March 3 unless you add the 'floor' modifier (3.46+).
  • Oracle has two behaviours. ADD_MONTHS(DATE '2026-01-31', 1) clamps to February 28, and ADD_MONTHS from a month's last day lands on the target's last day, so February 28 plus one month is March 31. DATE '2026-01-31' + INTERVAL '1' MONTH raises ORA-01839 instead.
  • Oracle adds days with plain +: d + 1 is tomorrow and d + 1/24 is an hour later.
  • SQLite chains modifiers left to right: date(created_at, 'start of month', '+1 month', '-1 day') is the last day of the month.

Questions about DATEADD / DATE_ADD

What happens when I add a month to January 31?

SQL Server, MySQL, PostgreSQL and Oracle's ADD_MONTHS clamp to the last day of February. Oracle's + INTERVAL '1' MONTH raises ORA-01839 instead, and SQLite returns March 3 (or March 2 in a leap year) unless you add the 'floor' modifier.

How do I add hours to a timestamp?

SQL Server: DATEADD(hour, 3, ts). MySQL: DATE_ADD(ts, INTERVAL 3 HOUR). PostgreSQL: ts + INTERVAL '3 hours'. SQLite: datetime(ts, '+3 hours'). Oracle: ts + INTERVAL '3' HOUR, or d + 3/24 for a DATE.

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

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