Datetime Functions
at_timezone
Returns the timestamp specified in timestamp with the time zone converted from the session time zone to the time zone specified in zone with precision p. In the following example, the session time zone is set to America/New_York, which is three hours ahead of America/Los_Angeles.
Supported Signatures
current_date
Returns the current date as of the start of the query.
Examples:
Supported Signatures
Note: current_date() is stable, i.e. might return a different value for a different query execution.
current_time
Returns the current time with time zone as of the start of the query.
Examples:
Supported Signatures
Note: current_time() is stable, i.e. might return a different value for a different query execution.
current_timestamp
Returns the current timestamp with time zone as of the start of the query, with 3 digits of subsecond precision,
Examples:
Supported Signatures
Note: current_timestamp() is stable, i.e. might return a different value for a different query execution.
current_timezone
Returns the current time zone in the format defined by IANA (e.g., America/Los_Angeles) or as fixed offset from UTC (e.g., +08.35)
Supported Signatures
Note: current_timezone() is stable, i.e. might return a different value for a different query execution.
date
This date(x)
is an alias for CAST(x AS date)
.
Examples:
Supported Signatures
date_add
Adds an interval value of type unit to timestamp. Subtraction can be performed by using a negative value.
Supported Signatures
date_diff
Takes a unit, timestamp1, and timestamp2. Returns timestamp2 - timestamp1 expressed in terms of unit.
Examples:
Supported Signatures
date_format
Formats timestamp as a string using format.
Examples:
Supported Signatures
date_parse
Parses string into a timestamp using format.
Supported Signatures
date_trunc
Returns the date x truncated to unit.
Examples:
Supported Signatures
day
Returns the day of the month from x.
Examples:
Supported Signatures
day_of_month
This is an alias for day().
Supported Signatures
day_of_week
Returns the ISO day of the week from x. The value ranges from 1 (Monday) to 7 (Sunday).
Supported Signatures
day_of_year
Returns the day of the year from x. The value ranges from 1 to 366.
Supported Signatures
dow
This is an alias for day_of_week().
Supported Signatures
doy
This is an alias for day_of_year().
Supported Signatures
format_datetime
Formats timestamp as a string using format.
Supported Signatures
from_iso8601_date
Parses the ISO 8601 formatted date string into a date. The date can be a calendar date, a week date using ISO week numbering, or year and day of year combined.
Supported Signatures
from_iso8601_timestamp
Parses the ISO 8601 formatted date string, optionally with time and time zone, into a timestamp(3) with time zone. The time defaults to 00.00.00.000, and the time zone defaults to the session time zone.
Supported Signatures
from_iso8601_timestamp_nanos
Parses the ISO 8601 formatted date and time string. The time zone defaults to the session time zone.
Supported Signatures
from_unixtime
Returns the UNIX timestamp unixtime as a timestamp with time zone. unixtime is the number of seconds since 1970-01-01 00.00.00 UTC.
Examples:
Supported Signatures
from_unixtime_nanos
Returns the UNIX timestamp unixtime as a timestamp with time zone. unixtime is the number of nanoseconds since 1970-01-01 00.00.00.000000000 UTC.
Supported Signatures
hour
Returns the hour of the day from x. The value ranges from 0 to 23.
Supported Signatures
human_readable_seconds
Formats the double value of seconds into a human readable string containing weeks, days, hours, minutes, and seconds.
Supported Signatures
last_day_of_month
Returns the last day of the month.
Supported Signatures
localtime
Returns the current time as of the start of the query.
Supported Signatures
Note: localtime() is stable, i.e. might return a different value for a different query execution.
localtimestamp
Returns the current timestamp as of the start of the query, with 3 digits of subsecond precision.
Supported Signatures
Note: localtimestamp() is stable, i.e. might return a different value for a different query execution.
millisecond
Returns the millisecond of the second from x.
Supported Signatures
minute
Returns the minute of the hour from x.
Supported Signatures
month
Returns the month of the year from x.
Examples:
Supported Signatures
now
This is an alias for current_timestamp.
Examples:
Supported Signatures
Note: now() is stable, i.e. might return a different value for a different query execution.
parse_datetime
Parses string into a timestamp with time zone using format.
Supported Signatures
parse_duration
Parses string of format value unit into an interval, where value is fractional number of unit values.
Supported Signatures
quarter
Returns the quarter of the year from x. The value ranges from 1 to 4.
Supported Signatures
second
Returns the second of the minute from x.
Supported Signatures
timezone_hour
Returns the hour of the time zone offset from timestamp.
Supported Signatures
timezone_minute
Returns the minute of the time zone offset from timestamp.
Supported Signatures
to_iso8601
Formats x as an ISO 8601 string. x can be date, timestamp, or timestamp with time zone.
Supported Signatures
to_milliseconds
Returns the day-to-second interval as milliseconds.
Supported Signatures
to_unixtime
Returns timestamp as a UNIX timestamp.
Examples:
Supported Signatures
week
Returns the ISO week of the year from x. The value ranges from 1 to 53.
Supported Signatures
week_of_year
This is an alias for week().
Supported Signatures
with_timezone
Returns the timestamp specified in timestamp with the time zone specified in zone with precision p.
Supported Signatures
year
Returns the year from x.
Examples:
Supported Signatures
year_of_week
Returns the year of the ISO week from x.
Supported Signatures
yow
This is an alias for year_of_week().
Supported Signatures