SQL ADDDATE function
Adds a number of days, or any INTERVAL unit, to a date or datetime. With an INTERVAL argument it is a synonym for DATE_ADD.
- Returns
date / datetime- In this category
- 65 of 121
语法
ADDDATE(date, days)
ADDDATE(date, INTERVAL n unit)
Each block is a separate form. The support table and the examples show which engine takes which.
引擎支持
| 引擎 | Support | 备注 |
|---|---|---|
| SQL Server | Different name or syntax | DATEADD(day, n, d) or DATEADD(month, n, d) |
| PostgreSQL | Different name or syntax | d + INTERVAL '1 day' / d + INTERVAL '1 month' |
| MySQL | Different name or syntax | See the examples and notes below. |
| SQLite | 是 | date(d, '+7 days') |
| Oracle | Different name or syntax | d + INTERVAL '1' DAY or ADD_MONTHS(d, 1) |
示例
MySQL
SELECT ADDDATE('2026-01-31', INTERVAL 1 MONTH); -- 2026-02-28
MySQL
SELECT ADDDATE('2026-08-01', 7); -- 2026-08-08
PostgreSQL
SELECT DATE '2026-01-31' + INTERVAL '1 month'; -- 2026-02-28 00:00:00
值得了解
- Month arithmetic clamps in MySQL: ADDDATE('2026-01-31', INTERVAL 1 MONTH) gives 2026-02-28, not a March 3 overflow.
- ADDDATE(d, 7) with a bare number always means days; only the INTERVAL form takes other units.
- Oracle's ADD_MONTHS differs at month ends: ADD_MONTHS(DATE '2026-02-28', 1) is 2026-03-31, while ADDDATE('2026-02-28', INTERVAL 1 MONTH) is 2026-03-28.
Questions about ADDDATE
Is ADDDATE the same as DATE_ADD?
With an INTERVAL argument, yes: ADDDATE is a synonym for DATE_ADD. Only ADDDATE accepts a bare day count: DATE_ADD('2026-08-01', 7) is a syntax error.
How do I add a month in PostgreSQL?
date + INTERVAL '1 month'. PostgreSQL clamps the day to the month's last day, so 2026-01-31 plus one month is 2026-02-28.
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: SQL Server, PostgreSQL, MySQL, SQLite, 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.