DATE
This function parses the argument using the specified format if specified.
SYNTAX​
DATE ( arg [ , <format_modifier>, format] )
<format_modifier> ::=
"FORMAT"
ARGUMENTS​
arg
A value to be converted to a date. 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​
The formatted date of DATE data type.
Remarks​
- When the arg is a numeric it is interpreted as the number of seconds since January 1, 1970 UTC.
- If a string is provided and "FORMAT" is not specified, the default format is
"2006-01-02"
Examples​
This example interprets the provided datetime string using the format provided, and converts it to a date.
SELECT DATE("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 [DATE]
2021-05-12