DATEADD(date_part, interval, date) adds a whole number of date_part units to a date: DATEADD('month', 1, #2025-01-31#) is 28 February 2025, because a month added to a month end clamps to the last day that exists. In DuckDB, add an INTERVAL: Ordered + INTERVAL 1 MONTH clamps the same way. A date stays a date in Tableau; in DuckDB, cast it back.
Updated · Checked on the xmetric engine
What is the syntax?
DATEADD(date_part, interval, date)
date_part
a quoted string: 'second', 'minute', 'hour', 'day', 'week', 'month', 'quarter', 'year', or 'weekday', 'dayofyear', 'iso-week', 'iso-weekday'.
interval
a whole number, negative to go back in time.
date
a date or date-time.
Returns a date or date-time: date moved by interval units of date_part. Null if either is null.
What does it return, and what is the SQL?
Each example runs on the same 9 sample rows twice: the Tableau formula on the xmetric engine, and the SQL in DuckDB.
What is the date one month after each order?
Tableau
DATEADD('month', 1, [Ordered])
SQL (DuckDB)
SELECT Ordered +INTERVAL1 MONTH AS result
FROM input
ORDERBY id
Order 6 on 31 January 2025 lands on 28 February: there is no 31 February, so the day clamps to the month end.
Ordered
Result
2021-01-0108:00
2021-02-0108:00
2021-01-0318:45
2021-02-0318:45
2024-02-2910:15
2024-03-2910:15
2024-12-2916:25:40
2025-01-2916:25:40
2024-12-3009:05
2025-01-3009:05
2025-01-3123:59:59
2025-02-2823:59:59
2025-03-0100:00
2025-04-0100:00
2025-03-0212:30:15
2025-04-0212:30:15
null
✓ The Tableau formula and the SQL return the same 9 rows.
What is the date one year after a leap day?
Tableau
DATEADD('year', 1, [Ordered])
SQL (DuckDB)
SELECT Ordered +INTERVAL1 YEAR AS result
FROM input
ORDERBY id
Order 3 on 29 February 2024 lands on 28 February 2025.
Ordered
Result
2021-01-0108:00
2022-01-0108:00
2021-01-0318:45
2022-01-0318:45
2024-02-2910:15
2025-02-2810:15
2024-12-2916:25:40
2025-12-2916:25:40
2024-12-3009:05
2025-12-3009:05
2025-01-3123:59:59
2026-01-3123:59:59
2025-03-0100:00
2026-03-0100:00
2025-03-0212:30:15
2026-03-0212:30:15
null
✓ The Tableau formula and the SQL return the same 9 rows.
What is the due date plus 18 hours?
Tableau
DATEADD('hour', 18, [Due])
SQL (DuckDB)
SELECT Due +INTERVAL18 HOUR AS result
FROM input
ORDERBY id
Adding hours to a date gives a date-time: 18:00 on the due date.
Due
Result
2021-01-01
2021-01-0118:00
2021-01-03
2021-01-0318:00
2024-02-29
2024-02-2918:00
2024-12-29
2024-12-2918:00
2024-12-30
2024-12-3018:00
2025-01-31
2025-01-3118:00
2025-03-01
2025-03-0118:00
2025-03-02
2025-03-0218:00
null
✓ The Tableau formula and the SQL return the same 9 rows.
Where does a straight translation go wrong?
Common mistake
Why is adding 30 days not the same as adding a month?
Months have 28 to 31 days. DATEADD moves to the same day of the next month (clamped at month end), so 31 January becomes 28 February, while 30 days lands on 2 March.
Tableau
DATEADD('month', 1, [Ordered])
Tempting SQL
SELECT Ordered +INTERVAL30 DAY AS result
FROM input
ORDERBY id
SQL that matches
SELECT Ordered +INTERVAL1 MONTH AS result
FROM input
ORDERBY id
Ordered
Tableau
Tempting SQL
SQL that matches
2021-01-0108:00
2021-02-0108:00
2021-01-3108:00
2021-02-0108:00
2021-01-0318:45
2021-02-0318:45
2021-02-0218:45
2021-02-0318:45
2024-02-2910:15
2024-03-2910:15
2024-03-3010:15
2024-03-2910:15
2024-12-2916:25:40
2025-01-2916:25:40
2025-01-2816:25:40
2025-01-2916:25:40
2024-12-3009:05
2025-01-3009:05
2025-01-2909:05
2025-01-3009:05
2025-01-3123:59:59
2025-02-2823:59:59
2025-03-0223:59:59
2025-02-2823:59:59
2025-03-0100:00
2025-04-0100:00
2025-03-3100:00
2025-04-0100:00
2025-03-0212:30:15
2025-04-0212:30:15
2025-04-0112:30:15
2025-04-0212:30:15
null
null
null
✓ The SQL that matches returns the Tableau result on every row; the marked cells are where the tempting SQL differs.
Common mistake
Why does adding a month to a date column give a timestamp?
In DuckDB, DATE + INTERVAL returns a timestamp. Tableau keeps a date a date when you add days, weeks, months or years, so cast back to DATE.
Tableau
DATEADD('month', 1, [Due])
Tempting SQL
SELECT Due +INTERVAL1 MONTH AS result
FROM input
ORDERBY id
SQL that matches
SELECTCAST (Due +INTERVAL1 MONTH AS DATE) AS result
FROM input
ORDERBY id
Due
Tableau
Tempting SQL
SQL that matches
2021-01-01
2021-02-01
2021-02-0100:00
2021-02-01
2021-01-03
2021-02-03
2021-02-0300:00
2021-02-03
2024-02-29
2024-03-29
2024-03-2900:00
2024-03-29
2024-12-29
2025-01-29
2025-01-2900:00
2025-01-29
2024-12-30
2025-01-30
2025-01-3000:00
2025-01-30
2025-01-31
2025-02-28
2025-02-2800:00
2025-02-28
2025-03-01
2025-04-01
2025-04-0100:00
2025-04-01
2025-03-02
2025-04-02
2025-04-0200:00
2025-04-02
null
null
null
✓ The SQL that matches returns the Tableau result on every row; the marked cells are where the tempting SQL differs.
What does each date part add, and what is its SQL?
One unit of each date part added to the same order dates. Weeks are 7 days; the weekday and day-of-year parts add plain days. Columns 1 to 9 are the sample rows, by id.
Case
Tableau, then SQL (DuckDB)
1
2
3
4
5
6
7
8
9
second
DATEADD('second', 1, [Ordered])Ordered + INTERVAL 1 SECOND