Query
SELECT
id,
name,
registered_at,
date(registered_at, '+30 days') AS review
FROM customers
ORDER BY id
LIMIT 5;The modifier '+30 days' is applied to the value of registered_at. To subtract, use a negative offset such as '-7 days'.
How adding and subtracting dates works in SQL
“Adding 30” to a date does not say whether you mean days, hours or months. A date operation must make the unit and the starting value clear, which also avoids confusing date arithmetic with ordinary arithmetic.
For business deadlines, also ask whether you need calendar days, calendar months or an exact number of hours. They are not always interchangeable.
Cases that change the result
Months and years: the end of the month matters
A month does not have a fixed number of days. That is why “31 January + 1 month” forces the engine to resolve a date that may not exist in February. PostgreSQL and MySQL document how they adjust at month end; SQLite provides modifiers and options such as ceiling/floor to resolve ambiguities when shifting by months or years.
For legal or billing deadlines, do not assume the rule. Decide what “one month later” means in your business, create test cases for month ends and leap years, and document how the engine behaves.
A calendar day and 24 hours can differ
With time-zone-aware timestamps, adding a calendar “day” and adding exactly 24 hours can give different local times across a daylight saving change. PostgreSQL documents this explicitly for timestamp with time zone. If your application works across time zones, keep the calendar requirement separate from the duration requirement.
Storing ambiguous dates as text and then doing arithmetic
A string such as 03/04/2026 can be read in several ways. Use real date/time types where the engine offers them, or unambiguous formats in SQLite, and validate the time zone when it is part of the meaning.
Key differences between engines
PostgreSQL
SELECT registered_at + INTERVAL '30 days' AS review
FROM customers;PostgreSQL defines interval types and date/time operators. When you add an interval that includes a time to a date, the result can become a timestamp.
MySQL
SELECT DATE_ADD(registered_at, INTERVAL 30 DAY) AS review
FROM customers;
SELECT DATE_SUB(registered_at, INTERVAL 7 DAY) AS previous_week
FROM customers;SQL Server
SELECT DATEADD(day, 30, registered_at) AS review
FROM customers;
SELECT DATEADD(day, -7, registered_at) AS previous_week
FROM customers;Do not copy a variant into another engine and expect it to behave the same. The function name, the interval syntax and the date/time types are all part of the dialect.