メインコンテンツまでスキップ

try_make_timestamp function

Applies to: check marked yes Databricks SQL check marked yes 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: An INTEGER expression from 1 through 9999.
  • month: An INTEGER expression from 1 (January) through 12 (December).
  • day: An INTEGER expression from 1 through 31.
  • hour: An INTEGER expression from 0 through 23.
  • min: An INTEGER expression from 0 through 59.
  • sec: A numeric expression from 0 through 60.
  • date: A DATE expression that provides the year, month, and day fields.
  • time: An optional TIME expression that provides the hour, minute, and second fields. The default is 00:00:00.
  • timezone: An optional STRING expression that evaluates to a valid time zone, such as CET or UTC.

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