// dialect comparison

Add months to a date in SQL Server, PostgreSQL, MySQL, SQLite and Oracle

Jan 31 plus one month is Feb 28 in four engines, Mar 3 in SQLite, and an error with Oracle's INTERVAL form.

Filed under Types & casting

The verdict

SQL Server, PostgreSQL, MySQL and Oracle's ADD_MONTHS clamp Jan 31 + 1 month to Feb 28/29. SQLite rolls into March unless you add 'floor', and Oracle's INTERVAL form errors. ADD_MONTHS also snaps month-end inputs to month ends, so test month-end dates explicitly.

Where they differ

Adding months is trickier than adding days because month lengths differ. Each engine has a rule for what Jan 31 + 1 month means, and they do not all agree.

How each engine writes it

SQL Server

SELECT DATEADD(MONTH, 3, '2026-11-20');

Adds calendar months and clamps: DATEADD(MONTH, 1, '2026-01-31') is 2026-02-28. It keeps the day number otherwise, so Feb 28 + 1 month is Mar 28.

PostgreSQL

SELECT DATE '2026-11-20' + INTERVAL '3 months';

Jan 31 + 1 month gives Feb 28: interval arithmetic clamps to the end of the target month.

MySQL

SELECT DATE_ADD('2026-11-20', INTERVAL 3 MONTH);

Clamps to month end: Jan 31 + 1 month is Feb 28/29.

SQLite

SELECT DATE('2026-11-20', '+3 months');

Does not clamp: '+1 month' on 2026-01-31 builds Feb 31, which normalizes forward to 2026-03-03. SQLite 3.46+ accepts a 'floor' modifier, DATE(d, '+1 month', 'floor'), that clamps to Feb 28 instead.

Oracle

SELECT ADD_MONTHS(DATE '2026-11-20', 3) FROM dual;

ADD_MONTHS clamps, and a month-end input always maps to the target month's last day (Feb 28 + 1 month is Mar 31). DATE '2026-01-31' + INTERVAL '1' MONTH raises ORA-01839 instead.

Questions that come up

Why does SQLite give Mar 3 for Jan 31 + 1 month?

SQLite adds 1 to the month field and keeps day 31. Feb 31 does not exist, so it normalizes forward to Mar 3. On 3.46 and later, append the 'floor' modifier to clamp to Feb 28 instead.

When does Oracle's INTERVAL month form fail?

SYSDATE + INTERVAL '1' MONTH raises ORA-01839 on a date whose day does not exist in the target month. ADD_MONTHS handles it by clamping, so most shops standardize on ADD_MONTHS.

Do all engines agree on clamping otherwise?

SQL Server, PostgreSQL and MySQL clamp to the last day of the target month and otherwise keep the day number. Oracle's ADD_MONTHS also maps any month-end input to a month end, so ADD_MONTHS(DATE '2026-02-28', 1) is Mar 31 while DATEADD gives Mar 28. SQLite is the outlier that overflows.

Keep reading

// write it once, run it anywhere

Switch engines without relearning SQL

SQLly is a native SQL workbench for macOS, Windows and Linux. Its formatter and plan viewer work in all five dialects.