Convert a string to timestamp

Supported in: Batch, Streaming

Returns the timestamp given a formatted string in accordance to the Java DateTimeFormatter. The default formats are yyyy-MM-dd'T'HH:mm:ss.SSSXXX and yyyy-MM-dd. The formats are run in order, the first matching format will be returned.

Expression categories: Cast, Datetime

Declared arguments

  • String - String column to convert to timestamp.
    Expression<String>
  • optional Formats - Format defaults to ISO8601 yyyy-MM-dd'T'HH:mm:ss.SSSXXX and yyyy-MM-dd.
    List<Literal<String>>
  • optional Time zone - Used to parse formats that do not include a timezone. If the format also includes a zone, this parameter will override it - see examples for details.
    TimeZone

Output type: Timestamp

Examples

Example 1: Base case

Argument values:

  • String: timestamp
  • Formats: [yyyy-MM-dd'T'HH:mm.SSSSSSX]
  • Time zone: null
timestampOutput
2020-04-28T01:30:02.005110Z2020-04-28T01:30:02.00511Z

Example 2: Base case

Argument values:

  • String: timestamp
  • Formats: null
  • Time zone: null
timestampOutput
2020-04-28T01:30:02.005Z2020-04-28T01:30:02.005Z

Example 3: Base case

Argument values:

  • String: timestamp
  • Formats: null
  • Time zone: null
timestampOutput
2020-04-282020-04-28T00:00:00Z

Example 4: Base case

Argument values:

  • String: timestamp
  • Formats: [dd-yyyy-MM HH:mm, yyyy-MM-dd]
  • Time zone: null
timestampOutput
28-2020-04 10:09:002020-04-28T10:09:00Z
2020-04-282020-04-28T00:00:00Z

Example 5: Base case

Argument values:

  • String: timestamp
  • Formats: [yyyy-DDD HH:mm]
  • Time zone: null
timestampOutput
2022-334 10:09:002022-11-30T10:09:00Z

Example 6: Base case

Argument values:

  • String: timestamp
  • Formats: [dd MMMM yyyy HH:mm]
  • Time zone: null
timestampOutput
30 November 2022 10:09:002022-11-30T10:09:00Z

Example 7: Base case

Argument values:

  • String: timestamp
  • Formats: [yyyy-MM-dd h:mm a]
  • Time zone: null
timestampOutput
2022-11-30 1:30:00 PM2022-11-30T13:30:00Z

Example 8: Base case

Argument values:

  • String: timestamp
  • Formats: [yyyy-MM-dd HH:m]
  • Time zone: null
timestampOutput
2022-11-30 13:9:002022-11-30T13:09:00Z

Example 9: Base case

Argument values:

  • String: timestamp
  • Formats: [dd-MMM-yyyy HH:mm]
  • Time zone: null
timestampOutput
30-Nov-2022 10:09:002022-11-30T10:09:00Z

Example 10: Base case

Argument values:

  • String: timestamp
  • Formats: [yyyy-DDD]
  • Time zone: null
timestampOutput
2022-3342022-11-30T00:00:00Z

Example 11: Base case

Argument values:

  • String: timestamp
  • Formats: [yyyy-MM-dd HH:mm]
  • Time zone: null
timestampOutput
2022-11-30 13:09:02022-11-30T13:09:00Z

Example 12: Base case

Argument values:

  • String: timestamp
  • Formats: [yy-MM-dd HH:mm]
  • Time zone: null
timestampOutput
22-11-30 10:09:002022-11-30T10:09:00Z

Example 13: Base case

Argument values:

  • String: timestamp
  • Formats: [dd-MMM-yyyy HH:mm]
  • Time zone: null
timestampOutput
01-Nov-2023 10:09:002023-11-01T10:09:00Z

Example 14: Base case

Argument values:

  • String: timestamp
  • Formats: [dd-MMM-yyyy HH:mm]
  • Time zone: null
timestampOutput
01-NOV-2023 10:09:002023-11-01T10:09:00Z

Example 15: Base case

Argument values:

  • String: timestamp
  • Formats: [yyyy-MM-dd HH:mm z]
  • Time zone: null
timestampOutput
2022-11-30 10:09:00 PST2022-11-30T18:09:00Z

Example 16: Base case

Argument values:

  • String: timestamp
  • Formats: [yyyy-MM-dd'T'HH:mm.SSS;z]
  • Time zone: null
timestampOutput
2022-11-29T09:50:04.187;EST2022-11-29T14:50:04.187Z

Example 17: Base case

Argument values:

  • String: timestamp
  • Formats: [yyyy-MM-dd'T'HH:mm.SSSXXX]
  • Time zone: null
timestampOutput
2022-11-29T09:50:04.187-05:002022-11-29T14:50:04.187Z

Example 18: Base case

Argument values:

  • String: timestamp
  • Formats: [dd-yyyy-MM HH:mm]
  • Time zone: Australia/Sydney
timestampOutput
28-2020-04 04:12:002020-04-28T04:12:00+10:00

Example 19: Base case

Argument values:

  • String: timestamp
  • Formats: [dd-yyyy-MM HH:mm]
  • Time zone: +10
timestampOutput
28-2020-04 04:12:002020-04-28T04:12:00+10:00

Example 20: Null case

Argument values:

  • String: timestamp
  • Formats: [dd-yyyy-MM HH:mm, yyyy-MM-dd]
  • Time zone: null
timestampOutput
202021-04-28null

Example 21: Edge case

Argument values:

  • String: timestamp
  • Formats: [yyyy-MM-dd'T'HH:mm.SSS;v]
  • Time zone: null
timestampOutput
2022-11-29T09:50:04.187;Australia/Sydney2022-11-28T22:50:04.187Z

Example 22: Edge case

Argument values:

  • String: timestamp
  • Formats: [yyyy-MM-dd'T'HH:mm.SSS;z]
  • Time zone: Australia/Sydney
timestampOutput
2022-11-29T09:50:04.187;EST2022-11-28T22:50:04.187Z

Example 23: Edge case

Argument values:

  • String: timestamp
  • Formats: [yyyy-MM-dd hh:mm a]
  • Time zone: null
timestampOutput
2022-11-30 10:09:00 AM2022-11-30T10:09:00Z

Example 24: Edge case

Argument values:

  • String: timestamp
  • Formats: [yyyy-MM-dd hh:mm a]
  • Time zone: null
timestampOutput
2022-11-30 10:09:00 PM2022-11-30T22:09:00Z

Example 25: Edge case

Argument values:

  • String: timestamp
  • Formats: [yyyyDDD]
  • Time zone: UTC
timestampOutput
20230102023-01-10T00:00:00Z

Example 26: Edge case

Argument values:

  • String: timestamp
  • Formats: [yyyyDDD]
  • Time zone: EST
timestampOutput
20230102023-01-10T05:00:00Z

Example 27: Edge case

Argument values:

  • String: timestamp
  • Formats: [yyyyDDD]
  • Time zone: null
timestampOutput
20230102023-01-10T00:00:00Z

Example 28: Edge case

Argument values:

  • String: timestamp
  • Formats: [yyyyMMddHHmmss]
  • Time zone: UTC
timestampOutput
202301100000002023-01-10T00:00:00Z

Example 29: Edge case

Argument values:

  • String: timestamp
  • Formats: [yyyyMMddHHmmss]
  • Time zone: null
timestampOutput
202301100000002023-01-10T00:00:00Z

Example 30: Edge case

Argument values:

  • String: timestamp
  • Formats: [yyyy-MM-dd'T'HH:mm.SSSXXX;z]
  • Time zone: null
timestampOutput
2022-11-29T09:50:04.187Z;EST2022-11-29T09:50:04.187Z

Example 31: Edge case

Argument values:

  • String: timestamp
  • Formats: [yyyy-MM-dd'T'HH:mm.SSSSSSX]
  • Time zone: null
timestampOutput
2020-04-28T01:30:02.005112Z2020-04-28T01:30:02.005112Z