Skip to main content

TIMESTAMP

This function parses the argument using the specified format if specified.

SYNTAX​

TIMESTAMP ( arg [ , <format_modifier>,  format] )  

<format_modifier> ::=
"FORMAT"
| "ZONE"

ARGUMENTS​

arg A value to be converted to a timestamp. Valid arguments are numeric, date/time values, and strings. If a format is specified arg must be of type STRING.

format_modifier
Specifies how the format argument should be interpreted.

format
An optional string argument to specify how the arg should be interpreted.

Return Value​

A time to nanosecond precision of TIMESTAMP data type.

Remarks​

  • When the arg is a numeric it is interpreted as the number of nanoseconds since January 1, 1970 UTC.
  • The TIMESTAMP datatype has a smaller date range than the DATETIME datatype and should be used as an alternative if more percision is needed.
  • If a string is provided and "FORMAT" is not specified, the default format is "2006-01-02 15:04:05.000000000"
  • If "ZONE" is specified, the format must be "UTC" or a location name corresponding to a file in the IANA Time Zone database, such as "America/Los_Angeles".

Examples​

This example interprets the provided string using the format provided, outputting its full representation.

SELECT TIMESTAMP("2021-05-12 08:06:25", "FORMAT", "2006-01-02 15:04:05") AS formatted;

For a list of golang time formats see the time package.

Response:

FORMATTED [TIMESTAMP]
2021-05-12 08:06:25.000000000