Tableau function Date

Tableau MAKEDATETIME to SQL

MAKEDATETIME(date, time) returns a date-time: the date from the first argument and the time of day from the second, which can be a time literal or a date-time. In DuckDB add the time to the date: Due + CAST(Ordered AS TIME). Rebuilding the time from hours and minutes drops the seconds.

Updated · Checked on the xmetric engine

What is the syntax?

MAKEDATETIME(date, time)
date
a date, or a date-time whose time is ignored.
time
a time literal such as #07:59:00#, or a date-time whose date is ignored.

Returns a date-time: the date of date at the time of day of time. 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 date-time does the due date at the order's time of day make?

Tableau

MAKEDATETIME([Due], [Ordered])

SQL (DuckDB)

SELECT Due + CAST (Ordered AS TIME) AS result
FROM input
ORDER BY id

Casting the date-time to TIME keeps hours, minutes and seconds; adding it to a date gives a timestamp.

OrderedDueResult
2021-01-01 08:002021-01-012021-01-01 08:00
2021-01-03 18:452021-01-032021-01-03 18:45
2024-02-29 10:152024-02-292024-02-29 10:15
2024-12-29 16:25:402024-12-292024-12-29 16:25:40
2024-12-30 09:052024-12-302024-12-30 09:05
2025-01-31 23:59:592025-01-312025-01-31 23:59:59
2025-03-01 00:002025-03-012025-03-01 00:00
2025-03-02 12:30:152025-03-022025-03-02 12:30:15
null

The Tableau formula and the SQL return the same 9 rows.

What is the same time on the next day?

Tableau

MAKEDATETIME(DATEADD('day', 1, [Due]), [Ordered])

SQL (DuckDB)

SELECT
  CAST (Due + INTERVAL 1 DAY AS DATE)
    + CAST (Ordered AS TIME) AS result
FROM input
ORDER BY id

Move the date part, keep the time part. Order 3 on the leap day moves to 1 March 2024.

OrderedDueResult
2021-01-01 08:002021-01-012021-01-02 08:00
2021-01-03 18:452021-01-032021-01-04 18:45
2024-02-29 10:152024-02-292024-03-01 10:15
2024-12-29 16:25:402024-12-292024-12-30 16:25:40
2024-12-30 09:052024-12-302024-12-31 09:05
2025-01-31 23:59:592025-01-312025-02-01 23:59:59
2025-03-01 00:002025-03-012025-03-02 00:00
2025-03-02 12:30:152025-03-022025-03-03 12:30:15
null

The Tableau formula and the SQL return the same 9 rows.

Where does a straight translation go wrong?

Common mistake

Why does rebuilding the time from hours and minutes drift?

Adding hour() and minute() drops the seconds: 16:25:40 becomes 16:25:00 and 23:59:59 becomes 23:59:00. MAKEDATETIME keeps the full time; cast to TIME instead.

Tableau

MAKEDATETIME([Due], [Ordered])

Tempting SQL

SELECT
  Due
    + to_hours(hour(Ordered))
    + to_minutes(minute(Ordered)) AS result
FROM input
ORDER BY id

SQL that matches

SELECT Due + CAST (Ordered AS TIME) AS result
FROM input
ORDER BY id
OrderedDueTableauTempting SQLSQL that matches
2021-01-01 08:002021-01-012021-01-01 08:002021-01-01 08:002021-01-01 08:00
2021-01-03 18:452021-01-032021-01-03 18:452021-01-03 18:452021-01-03 18:45
2024-02-29 10:152024-02-292024-02-29 10:152024-02-29 10:152024-02-29 10:15
2024-12-29 16:25:402024-12-292024-12-29 16:25:402024-12-29 16:252024-12-29 16:25:40
2024-12-30 09:052024-12-302024-12-30 09:052024-12-30 09:052024-12-30 09:05
2025-01-31 23:59:592025-01-312025-01-31 23:59:592025-01-31 23:592025-01-31 23:59:59
2025-03-01 00:002025-03-012025-03-01 00:002025-03-01 00:002025-03-01 00:00
2025-03-02 12:30:152025-03-022025-03-02 12:30:152025-03-02 12:302025-03-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.

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
  TIMESTAMP_NTZ_FROM_PARTS(Due, CAST (Ordered AS TIME)) AS result
FROM input
ORDER BY id

Snowflake documentation

BigQuery

SELECT DATETIME(Due, TIME(Ordered)) AS result
FROM input
ORDER BY id

BigQuery documentation

What does your own MAKEDATETIME 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 MAKEDATETIME?

Which connections support MAKEDATETIME?

Tableau's help says it is available only for MySQL-compatible connections; check your data source before relying on it.

Can the time be a literal?

Yes: MAKEDATETIME([Due], #18:00:00#) puts every due date at 6 pm. In SQL, Due + TIME '18:00:00'.

What if either argument is null?

The result is null, as on the blank last row.

Where is this documented?