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
to_timestamp(<string>, <format_pattern>)
Arguments
Required
<string>: Atextvalue representing the timestamp to parse.<format_pattern>: Atextvalue 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_TIMESTAMPwhen a simple cast can't handle your input format. For most standard date/time formats, cast the source string directly totimestampwithoutTO_TIMESTAMP. - The
YYYYpattern can't process a year with more than four digits. Use a non-digit separator afterYYYYfor 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.
SELECT 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.
SELECT to_timestamp('2024-03-15 14:30:00 -07', 'YYYY-MM-DD HH24:MI:SS TZH');
Returns 2024-03-15 14:30:00-07.