make_timestamp function
Applies to: Databricks SQL
Databricks Runtime
Creates a timestamp from year, month, day, hour, min, sec, and timezone fields.
Syntax
make_timestamp(year, month, day, hour, min, sec [, timezone] )
make_timestamp(date [, time [, timezone]] )
Beta
The time argument uses the TIME data type, which is in Beta.
Arguments
year: AnINTEGERexpression evaluating to a value from 1 to 9999.month: AnINTEGERexpression evaluating to a value from 1 (January) to 12 (December).day: AnINTEGERexpression evaluating to a value from 1 to 31.hour: AnINTEGERexpression evaluating to a value between 0 and 23.min: AnINTEGERexpression evaluating to a value between 0 and 59.sec: A numeric expression evaluating to a value between 0 and 60.date: ADATEexpression providing the year, month, and day fields.time: An optionalTIMEexpression providing the hour, minute, and second fields. Defaults to00:00:00if omitted.timezone: An optionalSTRINGexpression evaluating to a valid time zone, such asCETorUTC.
Returns
A TIMESTAMP.
If an argument is out of bounds, the function raises DATETIME_FIELD_OUT_OF_BOUNDS. Use try_make_timestamp to return NULL instead.
If sec is 60, the function interprets it as 0 and adds one minute to the result.
If sec has a fractional value that cannot be represented in microsecond precision, Databricks raises INVALID_FRACTION_OF_SECOND.
Common error conditions
Examples
SQL
> SELECT make_timestamp(2014, 12, 28, 6, 30, 45.887);
2014-12-28 06:30:45.887
> SELECT make_timestamp(2014, 12, 28, 6, 30, 45.887, 'CET');
2014-12-27 21:30:45.887
> SELECT make_timestamp(2019, 6, 30, 23, 59, 60);
2019-07-01 00:00:00
> SELECT make_timestamp(NULL, 7, 22, 15, 30, 0);
NULL
> SELECT make_timestamp(DATE'2014-12-28', TIME'06:30:45.887');
2014-12-28 06:30:45.887
> SELECT make_timestamp(DATE'2014-12-28', TIME'06:30:45.887', 'CET');
2014-12-27 21:30:45.887
> SELECT make_timestamp(DATE'2014-12-28');
2014-12-28 00:00:00
> SELECT make_timestamp(2024, 13, 1, 0, 0, 0);
Error: DATETIME_FIELD_OUT_OF_BOUNDS