SQL TIMESTAMPADD function
Adds an integer count of a named unit (SECOND, DAY, MONTH...) to a datetime, MySQL's ODBC-style spelling of DATEADD.
- Catégorie
- Dates & times
- Returns
datetime- In this category
- 69 of 121
Syntaxe
TIMESTAMPADD(unit, n, datetime)
Prise en charge des moteurs
| Moteur | Support | Notes |
|---|---|---|
| SQL Server | Different name or syntax | DATEADD(unit, n, d); closest match |
| PostgreSQL | Different name or syntax | d + make_interval(...) or d + INTERVAL 'n unit' |
| MySQL | Oui | Supported under this name. |
| SQLite | Different name or syntax | datetime(d, '+' || n || ' days') |
| Oracle | Different name or syntax | d + n * INTERVAL '1' DAY or ADD_MONTHS |
Exemples
MySQL
SELECT TIMESTAMPADD(MONTH, 3, '2026-08-01'); -- 2026-11-01
SQL Server
SELECT DATEADD(MONTH, 3, '2026-08-01');
Bon à savoir
- Units are bare keywords (MICROSECOND, SECOND, MINUTE, HOUR, DAY, WEEK, MONTH, QUARTER, YEAR), optionally prefixed with SQL_TSI_. The old FRAC_SECOND unit was removed in MySQL 5.5 and is now a syntax error.
- MONTH, QUARTER and YEAR clamp at month ends like DATE_ADD: TIMESTAMPADD(MONTH, 1, '2026-01-31') is 2026-02-28.
- The count must be an integer. For sub-second steps use the MICROSECOND unit: TIMESTAMPADD(MICROSECOND, 1500, d) adds 1.5 ms.
Questions about TIMESTAMPADD
TIMESTAMPADD vs DATE_ADD in MySQL?
Same result. TIMESTAMPADD uses the ODBC unit vocabulary (SQL_TSI_ names also work) and was kept for ODBC compatibility; DATE_ADD with INTERVAL is the idiomatic spelling.
What is the SQL Server equivalent?
DATEADD(MONTH, 3, d); the argument order moves the unit first, exactly like TIMESTAMPADD.
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.