See date and time operators for infix arithmetic.

SignatureDescription
current_date()Returns the current date.
date(...)Converts a timestamp or string to a date.
date_add(...)Adds a duration or time-unit interval to a date or timestamp.
date_bin(bucket_width_seconds, origin_seconds, timestamp)Truncates a timestamp onto a fixed-width grid of `bucket_width_seconds`, anchored at `origin_seconds` (seconds since the Unix epoch).
date_diff(unit, timestamp1, timestamp2)Returns the difference between two timestamps in the specified unit.
date_format(timestamp, format)Formats a timestamp as a string using the specified format.
date_trunc(unit, x)Truncates a timestamp to the specified time unit (e.g., day, month, year).
day(date)Extracts the day of the month from a date or timestamp.
day_of_month(date)Extracts the day of the month from a timestamp.
day_of_week(date)Extracts the day of the week from a timestamp.
day_of_year(date)Extracts the day of the month from a timestamp.
days_in_month(date)Returns the number of days in the month of the given date.
dow(date)Extracts the day of the week from a date or timestamp.
doy(date)Extracts the day of the year from a date or timestamp.
format_datetime(timestamp, format)Formats a datetime using a specified format string.
format_datetime_in_timezone(timestamp, format, timezone)Formats a UTC timestamp as a string using a Joda format pattern in the given IANA timezone.
from_iso8601_date(string)Parses an ISO 8601 date string into a date value.
from_iso8601_timestamp(string)Parses an ISO 8601 timestamp string into a datetime object.
from_unix_seconds(unixtime)Alias for from_unixtime.
from_unixtime(unixtime, ...)Converts a UNIX timestamp to a timestamp, optionally with a time zone offset.
hour(timestamp)Extracts the hour from a timestamp.
hour_in_timezone(timestamp, timezone)Extracts the hour from a timestamp on a given timezone.
is_business_day(date)Returns true if the date falls on a weekday (Monday-Friday).
is_federal_holiday(date)Returns True if the given timestamp is a federal holiday.
last_day_of_month(date)Returns the last day of the month for a given date.
make_date(year, month, day)Constructs a date from year, month, and day fields.
millisecond(timestamp)Extracts the millisecond from a timestamp.
minute(timestamp)Extracts the minute from a timestamp.
month(date)Extracts the month from a timestamp.
parse_datetime(string, format)Converts an ISO 8601 string into a datetime.
quarter(timestamp)Extracts the quarter of the year from a timestamp.
second(timestamp)Extracts the second from a timestamp.
to_days(days)Constructs a duration with the given number of days.
to_hours(hours)Constructs a duration with the given number of hours.
to_iso8601(timestamp)Converts a datetime to an ISO 8601 string format.
to_microseconds(...)Converts a duration to microseconds or constructs a duration from microseconds.
to_milliseconds(...)Converts a duration to milliseconds or constructs a duration from milliseconds.
to_minutes(minutes)Constructs a duration with the given number of minutes.
to_months(months)Constructs an interval with the given number of months.
to_seconds(seconds)Constructs a duration with the given number of seconds.
to_unix_nanos(timestamp)Converts a timestamp or date to nanoseconds since the Unix epoch (UTC). Throws if the value falls outside the int64 ns range (~1677 to ~2262).
to_unixtime(timestamp)Converts a timestamp to Unix timestamp (seconds since epoch).
to_years(years)Constructs an interval with the given number of years.
total_seconds(duration)Returns the length of the input duration in seconds.
week(date)Extracts the week of the year from a timestamp.
week_of_year(date)Extracts the week of the year from a timestamp.
year(date)Extracts the year from a timestamp.
year_of_week(date)Extracts the year of the ISO week from a date.
yow(date)Extracts the year of the ISO week from a date.
Returns the current date.
Parameters
None
Converts a timestamp or string to a date.
Examples
SELECT date('2024-01-02');
| date('2024-01-02') |
| ------------------ |
| 2024-01-02         |
Adds a duration or time-unit interval to a date or timestamp.
Examples
SELECT date_add('day', 7, TIMESTAMP '2024-01-02 00:00:00');
| date_add('day', 7, TIMESTAMP '2024-01-02 00:00:00') |
| --------------------------------------------------- |
| 2024-01-09 00:00:00                                 |
Truncates a timestamp onto a fixed-width grid of `bucket_width_seconds`, anchored at `origin_seconds` (seconds since the Unix epoch).
Parameters
timestamp:
timestamp[us, tz=UTC]
The input timestamp.
Returns the difference between two timestamps in the specified unit.
Parameters
unit:
large_string
The time unit, such as 'second', 'day', or 'month'.
timestamp1:
timestamp[us, tz=UTC]
The first timestamp.
timestamp2:
timestamp[us, tz=UTC]
The second timestamp.
Formats a timestamp as a string using the specified format.
Parameters
timestamp:
timestamp[us, tz=UTC]
The input timestamp.
format:
large_string
The format string.
Truncates a timestamp to the specified time unit (e.g., day, month, year).
Parameters
unit:
large_string
The time unit, such as 'second', 'day', or 'month'.
x:
timestamp[us, tz=UTC]
The input value.
Examples
SELECT date_trunc('month', TIMESTAMP '2024-02-15 13:45:00') AS month_start;
| month_start         |
| ------------------- |
| 2024-02-01 00:00:00 |
Extracts the day of the month from a date or timestamp.
Overloads
Extracts the day of the month from a timestamp.
Extracts the day of the week from a timestamp.
Extracts the day of the month from a timestamp.
Returns the number of days in the month of the given date.
Examples
SELECT days_in_month(DATE '2024-02-15') AS days;
| days |
| ---- |
| 29   |
Extracts the day of the week from a date or timestamp.
Overloads
Extracts the day of the year from a date or timestamp.
Overloads
Formats a datetime using a specified format string.
Parameters
timestamp:
timestamp[us, tz=UTC]
The input timestamp.
format:
large_string
The format string.
Formats a UTC timestamp as a string using a Joda format pattern in the given IANA timezone.
Parameters
timestamp:
timestamp[us, tz=UTC]
The input timestamp.
format:
large_string
The format string.
timezone:
large_string
The IANA timezone name, such as 'America/New_York'.
Parses an ISO 8601 date string into a date value.
Parameters
string:
large_string
The input string.
Parses an ISO 8601 timestamp string into a datetime object.
Parameters
string:
large_string
The input string.
Converts a UNIX timestamp to a timestamp, optionally with a time zone offset.
Examples
SELECT from_unixtime(1700000000);
| from_unixtime(1700000000) |
| ------------------------- |
| 2023-11-14 22:13:20 UTC   |
Extracts the hour from a timestamp.
Parameters
timestamp:
timestamp[us, tz=UTC]
The input timestamp.
Extracts the hour from a timestamp on a given timezone.
Parameters
timestamp:
timestamp[us, tz=UTC]
The input timestamp.
timezone:
large_string
The IANA timezone name, such as 'America/New_York'.
Returns true if the date falls on a weekday (Monday-Friday).
Returns True if the given timestamp is a federal holiday.
Returns the last day of the month for a given date.
Parameters
date:
timestamp[us, tz=UTC]
The input date or timestamp.
Constructs a date from year, month, and day fields.
Parameters
year:
int64
month:
int64
day:
int64
Extracts the millisecond from a timestamp.
Parameters
timestamp:
timestamp[us, tz=UTC]
The input timestamp.
Extracts the minute from a timestamp.
Parameters
timestamp:
timestamp[us, tz=UTC]
The input timestamp.
Extracts the month from a timestamp.
Converts an ISO 8601 string into a datetime.
Parameters
string:
large_string
The input string.
format:
large_string
The format string.
Extracts the quarter of the year from a timestamp.
Parameters
timestamp:
timestamp[us, tz=UTC]
The input timestamp.
Extracts the second from a timestamp.
Parameters
timestamp:
timestamp[us, tz=UTC]
The input timestamp.
Constructs a duration with the given number of days.
Constructs a duration with the given number of hours.
Converts a datetime to an ISO 8601 string format.
Parameters
timestamp:
timestamp[us, tz=UTC]
The input timestamp.
Examples
SELECT to_iso8601(TIMESTAMP '2024-01-02 03:04:05');
| to_iso8601(TIMESTAMP '2024-01-02 03:04:05') |
| ------------------------------------------- |
| 2024-01-02T03:04:05.000000Z                 |
Converts a duration to microseconds or constructs a duration from microseconds.
Converts a duration to milliseconds or constructs a duration from milliseconds.
Constructs a duration with the given number of minutes.
Constructs an interval with the given number of months.
Constructs a duration with the given number of seconds.
Converts a timestamp or date to nanoseconds since the Unix epoch (UTC). Throws if the value falls outside the int64 ns range (~1677 to ~2262).
Converts a timestamp to Unix timestamp (seconds since epoch).
Parameters
timestamp:
timestamp[us, tz=UTC]
The input timestamp.
Constructs an interval with the given number of years.
Returns the length of the input duration in seconds.
Parameters
duration:
duration[us]
The input duration.
Extracts the week of the year from a timestamp.
Extracts the week of the year from a timestamp.
Extracts the year from a timestamp.
Extracts the year of the ISO week from a date.
Extracts the year of the ISO week from a date.
Overloads