TO_TIMESTAMP

Applies to: ✅ Data 360 SQL ✅ Tableau Hyper API

Converts a formatted string to a timestamp with time zone value according to the supplied format pattern.

Syntax 

1to_timestamp(<string>, <format_pattern>)

Arguments 

Required 

  • <string>: A text value representing the timestamp to parse.
  • <format_pattern>: A text value specifying the format of the input string. Template pattern characters in the format string identify the corresponding parts of the input value.

Returns 

Returns timestamp with time zone.

Returns NULL if either argument is NULL.

Considerations 

  • For supported format pattern characters and modifiers, see TO_CHAR.
  • Use TO_TIMESTAMP when a simple cast can’t handle your input format. For most standard date/time formats, cast the source string directly to timestamp without TO_TIMESTAMP.
  • The YYYY pattern can’t process a year with more than four digits. Use a non-digit separator after YYYY for longer year values. For example, to_timestamp('20000-11-30', 'YYYY-MM-DD').
  • Millisecond (MS) and microsecond (US) fields are treated as the fractional seconds digits after the decimal point. For example, to_timestamp('12.3', 'SS.MS') produces 12.300 seconds (300 milliseconds), not 12.003.
  • ISO 8601 week-numbering fields (IYYY, IW, ID, IDDD) can’t be mixed with Gregorian date fields in the same call.

Examples 

Parse a Date String into a Timestamp 

Convert a human-readable date string to a timestamp with time zone.

1SELECT to_timestamp('05 Dec 2000', 'DD Mon YYYY');

Returns 2000-12-05 00:00:00+00.

Parse a Full Datetime String with Time Zone Offset 

Convert a string that includes time and time zone offset components.

1SELECT to_timestamp('2024-03-15 14:30:00 -07', 'YYYY-MM-DD HH24:MI:SS TZH');

Returns 2024-03-15 14:30:00-07.

Related Documentation