Skip to main content

Overview

The TO_TIMESTAMP() function converts a string into a timestamp based on the provided format. It returns a TIMESTAMP WITH TIME ZONE type.

Syntax

The syntax for using the TO_TIMESTAMP() function is as follows:
Let’s analyze the above syntax:
  • source: The date/time value to be converted. The value type is TIMESTAMP (YYYY-MM-DD HH:MM:SS).
  • format: The format of the input string.

Format

Format string supports following template patterns (can be lowercase):

Examples

Case #1: Timestamp into YYYY-MM-DD HH24:MI

The TO_TIMESTAMP() function converts the provided string into a timestamp with the format YYYY-MM-DD HH24:MI.
The final output will be a timestamp with a timezone.

Case #2: Timestamp into MM-DD HH12:MI

The TO_TIMESTAMP() function converts the provided string into a timestamp with the format MM-DD HH12:MI.
The final output will be a timestamp with a timezone.

Case #3: Timestamp into YYYY-MM HH12:MI(AM/PM)

The TO_TIMESTAMP()` function converts the provided string into a timestamp with the format YYYY-MM HH12:MI with meridiem indicator (AM/PM). Request 1
Request 2
The final output of both requests will have the same result. It changes the time into a 12-hour format, resulting in 12:30 being adjusted to 00:30.

Case #4: Timestamp into YYYY-MM-DD HH24:MI:SS.MS.US

The TO_TIMESTAMP() function converts the provided string into a timestamp with YYYY-MM-DD HH24:MI:SS.MS.US format.
The final output will be a timestamp with milliseconds and microseconds.

Case #5: Timestamp into YYYY-MM-DD HH24:MI:SS.MS

The TO_TIMESTAMP() function converts the provided string into a timestamp with YYYY-MM-DD HH24:MI:SS.MS format.
The final output will be a timestamp with milliseconds.