Tableau function Date

Tableau DATEADD to SQL

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 + INTERVAL 1 MONTH AS result
FROM input
ORDER BY id

Order 6 on 31 January 2025 lands on 28 February: there is no 31 February, so the day clamps to the month end.

OrderedResult
2021-01-01 08:002021-02-01 08:00
2021-01-03 18:452021-02-03 18:45
2024-02-29 10:152024-03-29 10:15
2024-12-29 16:25:402025-01-29 16:25:40
2024-12-30 09:052025-01-30 09:05
2025-01-31 23:59:592025-02-28 23:59:59
2025-03-01 00:002025-04-01 00:00
2025-03-02 12:30:152025-04-02 12: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 + INTERVAL 1 YEAR AS result
FROM input
ORDER BY id

Order 3 on 29 February 2024 lands on 28 February 2025.

OrderedResult
2021-01-01 08:002022-01-01 08:00
2021-01-03 18:452022-01-03 18:45
2024-02-29 10:152025-02-28 10:15
2024-12-29 16:25:402025-12-29 16:25:40
2024-12-30 09:052025-12-30 09:05
2025-01-31 23:59:592026-01-31 23:59:59
2025-03-01 00:002026-03-01 00:00
2025-03-02 12:30:152026-03-02 12: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 + INTERVAL 18 HOUR AS result
FROM input
ORDER BY id

Adding hours to a date gives a date-time: 18:00 on the due date.

DueResult
2021-01-012021-01-01 18:00
2021-01-032021-01-03 18:00
2024-02-292024-02-29 18:00
2024-12-292024-12-29 18:00
2024-12-302024-12-30 18:00
2025-01-312025-01-31 18:00
2025-03-012025-03-01 18:00
2025-03-022025-03-02 18: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 + INTERVAL 30 DAY AS result
FROM input
ORDER BY id

SQL that matches

SELECT Ordered + INTERVAL 1 MONTH AS result
FROM input
ORDER BY id
OrderedTableauTempting SQLSQL that matches
2021-01-01 08:002021-02-01 08:002021-01-31 08:002021-02-01 08:00
2021-01-03 18:452021-02-03 18:452021-02-02 18:452021-02-03 18:45
2024-02-29 10:152024-03-29 10:152024-03-30 10:152024-03-29 10:15
2024-12-29 16:25:402025-01-29 16:25:402025-01-28 16:25:402025-01-29 16:25:40
2024-12-30 09:052025-01-30 09:052025-01-29 09:052025-01-30 09:05
2025-01-31 23:59:592025-02-28 23:59:592025-03-02 23:59:592025-02-28 23:59:59
2025-03-01 00:002025-04-01 00:002025-03-31 00:002025-04-01 00:00
2025-03-02 12:30:152025-04-02 12:30:152025-04-01 12:30:152025-04-02 12:30:15
nullnullnull

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 + INTERVAL 1 MONTH AS result
FROM input
ORDER BY id

SQL that matches

SELECT CAST (Due + INTERVAL 1 MONTH AS DATE) AS result
FROM input
ORDER BY id
DueTableauTempting SQLSQL that matches
2021-01-012021-02-012021-02-01 00:002021-02-01
2021-01-032021-02-032021-02-03 00:002021-02-03
2024-02-292024-03-292024-03-29 00:002024-03-29
2024-12-292025-01-292025-01-29 00:002025-01-29
2024-12-302025-01-302025-01-30 00:002025-01-30
2025-01-312025-02-282025-02-28 00:002025-02-28
2025-03-012025-04-012025-04-01 00:002025-04-01
2025-03-022025-04-022025-04-02 00:002025-04-02
nullnullnull

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.

CaseTableau, then SQL (DuckDB)123456789
secondDATEADD('second', 1, [Ordered])Ordered + INTERVAL 1 SECOND2021-01-01 08:00:012021-01-03 18:45:012024-02-29 10:15:012024-12-29 16:25:412024-12-30 09:05:012025-02-01 00:002025-03-01 00:00:012025-03-02 12:30:16null
minuteDATEADD('minute', 1, [Ordered])Ordered + INTERVAL 1 MINUTE2021-01-01 08:012021-01-03 18:462024-02-29 10:162024-12-29 16:26:402024-12-30 09:062025-02-01 00:00:592025-03-01 00:012025-03-02 12:31:15null
hourDATEADD('hour', 1, [Ordered])Ordered + INTERVAL 1 HOUR2021-01-01 09:002021-01-03 19:452024-02-29 11:152024-12-29 17:25:402024-12-30 10:052025-02-01 00:59:592025-03-01 01:002025-03-02 13:30:15null
dayDATEADD('day', 1, [Ordered])Ordered + INTERVAL 1 DAY2021-01-02 08:002021-01-04 18:452024-03-01 10:152024-12-30 16:25:402024-12-31 09:052025-02-01 23:59:592025-03-02 00:002025-03-03 12:30:15null
weekDATEADD('week', 1, [Ordered])Ordered + INTERVAL 7 DAY2021-01-08 08:002021-01-10 18:452024-03-07 10:152025-01-05 16:25:402025-01-06 09:052025-02-07 23:59:592025-03-08 00:002025-03-09 12:30:15null
monthDATEADD('month', 1, [Ordered])Ordered + INTERVAL 1 MONTH2021-02-01 08:002021-02-03 18:452024-03-29 10:152025-01-29 16:25:402025-01-30 09:052025-02-28 23:59:592025-04-01 00:002025-04-02 12:30:15null
quarterDATEADD('quarter', 1, [Ordered])Ordered + INTERVAL 3 MONTH2021-04-01 08:002021-04-03 18:452024-05-29 10:152025-03-29 16:25:402025-03-30 09:052025-04-30 23:59:592025-06-01 00:002025-06-02 12:30:15null
yearDATEADD('year', 1, [Ordered])Ordered + INTERVAL 1 YEAR2022-01-01 08:002022-01-03 18:452025-02-28 10:152025-12-29 16:25:402025-12-30 09:052026-01-31 23:59:592026-03-01 00:002026-03-02 12:30:15null
dayofyearDATEADD('dayofyear', 1, [Ordered])Ordered + INTERVAL 1 DAY2021-01-02 08:002021-01-04 18:452024-03-01 10:152024-12-30 16:25:402024-12-31 09:052025-02-01 23:59:592025-03-02 00:002025-03-03 12:30:15null
weekdayDATEADD('weekday', 1, [Ordered])Ordered + INTERVAL 1 DAY2021-01-02 08:002021-01-04 18:452024-03-01 10:152024-12-30 16:25:402024-12-31 09:052025-02-01 23:59:592025-03-02 00:002025-03-03 12:30:15null
iso-weekDATEADD('iso-week', 1, [Ordered])Ordered + INTERVAL 7 DAY2021-01-08 08:002021-01-10 18:452024-03-07 10:152025-01-05 16:25:402025-01-06 09:052025-02-07 23:59:592025-03-08 00:002025-03-09 12:30:15null
iso-weekdayDATEADD('iso-weekday', 1, [Ordered])Ordered + INTERVAL 1 DAY2021-01-02 08:002021-01-04 18:452024-03-01 10:152024-12-30 16:25:402024-12-31 09:052025-02-01 23:59:592025-03-02 00:002025-03-03 12:30:15null

On every row, each Tableau formula and its SQL return the same value.

How do I write it in Snowflake or BigQuery?

The first example, written for each warehouse from its documentation. These are not run here; DuckDB is.

Snowflake

SELECT DATEADD(month, 1, Ordered) AS result
FROM input
ORDER BY id

Snowflake documentation

BigQuery

SELECT DATETIME_ADD(Ordered, INTERVAL 1 MONTH) AS result
FROM input
ORDER BY id

BigQuery documentation

What does your own DATEADD formula return?

Edit the formula and run it on the 9 sample rows. Fields: [id], [Ordered], [Due], [Text], [Local], [Y], [M], [D].

Runs in your browser on the xmetric engine. Nothing is uploaded.

Which functions go with it?

What do people ask about DATEADD?

How do I subtract time?

Use a negative interval: DATEADD('day', -7, [Ordered]); in SQL Ordered - INTERVAL 7 DAY.

Does 'weekday' skip weekends?

No. 'weekday', 'dayofyear' and 'iso-weekday' add calendar days, the same as 'day'. For business days, use a calendar table.

Can the interval be a field or a decimal?

A field works: DATEADD('day', [Lead Days], [Ordered]), in SQL Ordered + to_days([Lead Days]). Use a whole number; round a decimal first.

Where is this documented?