TO_TIMESTAMP_NTZ

to_timestamp_ntz(expr [, fmt])

Description

The TO_TIMESTAMP_NTZ function is used to convert different types of datetime expressions (expr) into a timestamp (timestamp_ntz) type. If the fmt parameter is provided, the function will parse according to the specified format; if fmt is not provided, it will convert according to the default format. If the datetime format in expr is incorrect, the function will return null.

Parameter Description

  • expr (string): The string expression to be converted.
  • fmt (string, optional): Specifies the format of the datetime in the string expression.

Return Result

The converted timestamp (timestamp_ntz).

Examples

  1. Convert a string to a timestamp according to the specified format:
SELECT to_timestamp_ntz('2022/02/01 10:23:32.121', 'yyyy/MM/dd HH:mm:ss.SSS') as ntz;
+-------------------------+
|           ntz           |
+-------------------------+
| 2022-02-01 10:23:32.121 |
+-------------------------+
  1. If the time format matches yyyy-MM-dd HH:mm:ss.SSS, then there is no need to specify the string format
SELECT to_timestamp_ntz('2022-02-01 10:23:32.121') ntz;
+-------------------------+
|           ntz           |
+-------------------------+
| 2022-02-01 10:23:32.121 |
+-------------------------+
3. Convert different types of date-time strings to timestamps:
SELECT to_timestamp_ntz('01-02 10:23:32', 'dd-MM HH:mm:ss') ntz;
+---------------------+
|         ntz         |
+---------------------+
| 1970-02-01 10:23:32 |
+---------------------+