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
ORDERBY id
Casting the date-time to TIME keeps hours, minutes and seconds; adding it to a date gives a timestamp.
Ordered
Due
Result
2021-01-0108:00
2021-01-01
2021-01-0108:00
2021-01-0318:45
2021-01-03
2021-01-0318:45
2024-02-2910:15
2024-02-29
2024-02-2910:15
2024-12-2916:25:40
2024-12-29
2024-12-2916:25:40
2024-12-3009:05
2024-12-30
2024-12-3009:05
2025-01-3123:59:59
2025-01-31
2025-01-3123:59:59
2025-03-0100:00
2025-03-01
2025-03-0100:00
2025-03-0212:30:15
2025-03-02
2025-03-0212: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)
SELECTCAST (Due +INTERVAL1 DAY AS DATE)
+CAST (Ordered AS TIME) AS result
FROM input
ORDERBY id
Move the date part, keep the time part. Order 3 on the leap day moves to 1 March 2024.
Ordered
Due
Result
2021-01-0108:00
2021-01-01
2021-01-0208:00
2021-01-0318:45
2021-01-03
2021-01-0418:45
2024-02-2910:15
2024-02-29
2024-03-0110:15
2024-12-2916:25:40
2024-12-29
2024-12-3016:25:40
2024-12-3009:05
2024-12-30
2024-12-3109:05
2025-01-3123:59:59
2025-01-31
2025-02-0123:59:59
2025-03-0100:00
2025-03-01
2025-03-0200:00
2025-03-0212:30:15
2025-03-02
2025-03-0312: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
ORDERBY id
SQL that matches
SELECT Due +CAST (Ordered AS TIME) AS result
FROM input
ORDERBY id
Ordered
Due
Tableau
Tempting SQL
SQL that matches
2021-01-0108:00
2021-01-01
2021-01-0108:00
2021-01-0108:00
2021-01-0108:00
2021-01-0318:45
2021-01-03
2021-01-0318:45
2021-01-0318:45
2021-01-0318:45
2024-02-2910:15
2024-02-29
2024-02-2910:15
2024-02-2910:15
2024-02-2910:15
2024-12-2916:25:40
2024-12-29
2024-12-2916:25:40
2024-12-2916:25
2024-12-2916:25:40
2024-12-3009:05
2024-12-30
2024-12-3009:05
2024-12-3009:05
2024-12-3009:05
2025-01-3123:59:59
2025-01-31
2025-01-3123:59:59
2025-01-3123:59
2025-01-3123:59:59
2025-03-0100:00
2025-03-01
2025-03-0100:00
2025-03-0100:00
2025-03-0100:00
2025-03-0212:30:15
2025-03-02
2025-03-0212:30:15
2025-03-0212:30
2025-03-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.
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
SELECTTIMESTAMP_NTZ_FROM_PARTS(Due, CAST (Ordered AS TIME)) AS result
FROM input
ORDERBY id