Date/Time Functions
Functions for manipulating and extracting information from date and time values.
CURRENT_DATE
Returns the current date when the query begins execution. This value remains constant throughout the query.
CURRENT_DATETIME
Returns the current date and time (timestamp) when the query begins execution. This value remains constant throughout the query.
CURRENT_TIMESTAMP
Returns the current date and time (timestamp with time zone) when the query begins execution. This value remains constant throughout the query.
DATE
Extracts the date part from a timestamp, datetime, or string, or casts a value to the DATE type. If the input is already a DATE, it is returned unchanged.
DATETIME
Casts the input value (date, timestamp, or string) to the DATETIME type.
TIMESTAMP
Casts the input value (date, datetime, or string) to the TIMESTAMP type.
DATE_TRUNCATE
Truncates a date/time value to the specified precision ('year', 'month', 'day', etc.). Returns a value of the same type as the input (or DATE if truncating to day or higher from a timestamp/datetime).
DATE_PART
Extracts a specific subfield (e.g., 'year', 'month', 'day', 'hour', 'dow' for day of week) from a date/time value as an integer.
DATE_ADD
Adds a specified integer interval to a date/time value. The unit of the interval is specified by the date part argument (e.g., day, month, year).
DATE_SUB
Subtracts a specified integer interval from a date/time value. The unit of the interval is specified by the date part argument.
DATE_DIFF
Calculates the integer difference between two date/time values, expressed in the units specified by the date part argument.
UNIX_TO_TIMESTAMP
Converts an integer Unix epoch timestamp (seconds since 1970-01-01 00:00:00 UTC) to a TIMESTAMP value.
SECOND
Extracts the second component (0-59) from a date/time value as an integer.
MINUTE
Extracts the minute component (0-59) from a date/time value as an integer.
HOUR
Extracts the hour component (0-23) from a date/time value as an integer.
DAY
Extracts the day of the month component (1-31) from a date/time value as an integer.
DAY_NAME
Extracts the name of the day of the week (e.g., 'Monday') from a date/time value.
WEEK
Extracts the ISO week number (1-53) from a date/time value as an integer.
MONTH
Extracts the month component (1-12) from a date/time value as an integer.
MONTH_NAME
Extracts the name of the month (e.g., 'January') from a date/time value.
QUARTER
Extracts the quarter component (1-4) from a date/time value as an integer.
YEAR
Extracts the year component from a date/time value as an integer.
DAY_OF_WEEK
Extracts the day of the week as an integer (e.g., Sunday=0 or 1, Monday=1 or 2, depending on locale/implementation - typically Sunday=0).
DATE_SPINE
Generates a continuous series of dates between a start and end date, inclusive. This is useful for creating date dimensions.
