TIMESTAMP_FROM_PARTS
functionsupportedCore SQL functionsCreates a timestamp from individual numeric components. If no time zone is in effect, the function can be used to create a timestamp from a date expression and a time expression.
Syntax
supportedpartialnot supportednot scored
TIMESTAMP_FROM_PARTS( <year>, <month>, <day>, <hour>, <minute>, <second> [, <nanosecond> ] [, <time_zone> ] )
TIMESTAMP_FROM_PARTS( <date_expr>, <time_expr> )
TIMESTAMP_LTZ_FROM_PARTS( <year>, <month>, <day>, <hour>, <minute>, <second> [, <nanosecond>] )
TIMESTAMP_NTZ_FROM_PARTS( <year>, <month>, <day>, <hour>, <minute>, <second> [, <nanosecond>] )
TIMESTAMP_NTZ_FROM_PARTS( <date_expr>, <time_expr> )
TIMESTAMP_TZ_FROM_PARTS( <year>, <month>, <day>, <hour>, <minute>, <second> [, <nanosecond>] [, <time_zone>] )
Parameters
| Name | Required | Description |
|---|---|---|
year | required | An integer expression to use as a year for building a timestamp. |
month | required | An integer expression to use as a month for building a timestamp, with January represented as 1, and December as 12. |
day | required | An integer expression to use as a day for building a timestamp, usually in the 1-31 range. |
hour | required | An integer expression to use as an hour for building a timestamp, usually in the 0-23 range. |
minute | required | An integer expression to use as a minute for building a timestamp, usually in the 0-59 range. |
second | required | An integer expression to use as a second for building a timestamp, usually in the 0-59 range. |
date_expr , time_expr | required | Specifies the date and time expressions to use for building a timestamp where date_expr provides the year, month, and day for the timestamp and time_expr provides the hour, minute, second, and nanoseconds within the day. Only valid for: TIMESTAMP_FROM_PARTS (when the TIMESTAMP_TYPE_MAPPING session parameter is set to TIMESTAMP_NTZ) TIMESTAMP_NTZ_FROM_PARTS |
nanoseconds | optional | An integer expression to use as a nanosecond for building a timestamp, usually in the 0-999999999 range. |
time_zone | optional | A string expression to use as a time zone for building a timestamp (e.g. America/Los_Angeles). Only valid for: TIMESTAMP_FROM_PARTS (when the TIMESTAMP_TYPE_MAPPING session parameter is set to TIMESTAMP_TZ) TIMESTAMP_TZ_FROM_PARTS |
Usage notes
- TIMESTAMP_FROM_PARTS variations are typically used to handle values in the “normal” value ranges (e.g. months 1-12, days 1-31, hours 0-23, etc.); however, they can also handle values from outside these ranges. This allows choosing the Nth day in a year or Nth second in a day, which can be useful for simplifying some computations.
- TIMESTAMP_FROM_PARTS is equivalent to the variation specified by the TIMESTAMP_TYPE_MAPPING session parameter (default is TIMESTAMP_NTZ).