try_make_timestamp function
Applies to: Databricks SQL
Databricks Runtime
Creates a timestamp from date and time fields, or returns NULL if the timestamp cannot be created.
Syntax
try_make_timestamp(year, month, day, hour, min, sec [, timezone] )
try_make_timestamp(date [, time [, timezone]] )
Beta
The time argument uses the TIME data type, which is in Beta.
Arguments
year: AnINTEGERexpression from1through9999.month: AnINTEGERexpression from1(January) through12(December).day: AnINTEGERexpression from1through31.hour: AnINTEGERexpression from0through23.min: AnINTEGERexpression from0through59.sec: A numeric expression from0through60.date: ADATEexpression that provides the year, month, and day fields.time: An optionalTIMEexpression that provides the hour, minute, and second fields. The default is00:00:00.timezone: An optionalSTRINGexpression that evaluates to a valid time zone, such asCETorUTC.
Returns
A TIMESTAMP, or NULL if an argument is out of bounds or the timestamp cannot be created.
If sec is 60, the function interprets it as 0 and adds one minute to the result.
Examples
SQL
> SELECT try_make_timestamp(2014, 12, 28, 6, 30, 45.887);
2014-12-28 06:30:45.887
> SELECT try_make_timestamp(2014, 13, 28, 6, 30, 45.887);
NULL
> SELECT try_make_timestamp(DATE'2014-12-28', TIME'06:30:45.887');
2014-12-28 06:30:45.887