Full answer
sql
SELECT date('2026-01-31', '+1 month') AS plus_one_month;| plus_one_month |
|---|
| 2026-03-03 |
sql
SELECT (DATE '2026-01-31' + INTERVAL '1 month')::date AS plus_one_month;| plus_one_month |
|---|
| 2026-02-28 |
SQLite adds to the month field and then normalizes the impossible date by rolling the extra days into the next month. PostgreSQL clamps to the end of the shorter month. Neither is wrong by the standard, but billing code that assumes one behaviour will drift on the other.
Since SQLite 3.46, modifiers ceiling and floor control this; floor clamps like PostgreSQL:
sql
SELECT date('2026-01-31', '+1 month', 'floor') AS floor_rule, date('2026-01-31', '+1 month', 'ceiling') AS ceiling_rule;| floor_rule | ceiling_rule |
|---|---|
| 2026-02-28 | 2026-03-03 |
When the rule is "same day next month, or the last day if it does not exist", write it explicitly, or compute from the start of the month.
sql
SELECT date('2026-01-31', '+1 month') AS plus_one_month;
SELECT date('2026-01-31', '+1 month', 'floor') AS floor_rule, date('2026-01-31', '+1 month', 'ceiling') AS ceiling_rule;Checked on SQLite 3.46.1, run twice with identical output. PostgreSQL results in the answer were checked on PostgreSQL 17.12.
Key points
- SQLite +1 month normalizes Feb 31 to 3 March
- PostgreSQL clamps to the last valid day
- SQLite 3.46 adds floor and ceiling modifiers
- State the month-end rule explicitly in billing logic
Common mistakes
- Assuming month arithmetic is portable
- Generating monthly due dates by repeatedly adding one month to the 31st
Follow-ups
- How would you produce the last day of each month?
- How would you generate monthly billing dates from a start date?
Tips
- Name both results and the reason