Date and time functions and operators in DuckDB
Use date and time functions and operators to get the current date and time and to read parts of a value, such as the year or the hour. You can also truncate values to a unit, add intervals, and count the units between two values.
The main date and time types in DuckDB are DATE, TIME, TIME WITH TIME ZONE, TIMESTAMP, TIMESTAMP WITH TIME ZONE, and INTERVAL. A DATE is a calendar date. A TIME is a time of day without a date. A TIME WITH TIME ZONE, which you can also write as TIMETZ, is a time of day that keeps the UTC offset that you write. A TIMESTAMP is a date and time without a time zone. A TIMESTAMP WITH TIME ZONE, which you can also write as TIMESTAMPTZ, is an instant in time. An INTERVAL is a length of time. Write literals with the type name, as in DATE '2026-11-18', TIME '10:30:00', TIMESTAMP '2026-11-18 10:30:00', TIMESTAMPTZ '2026-11-18 10:30:00-08', INTERVAL 90 MINUTE, and INTERVAL '2 hours 30 minutes'. The date and time functions do not convert a VARCHAR value, such as a string column, to a date for you. They convert a string literal such as '2026-11-18' only in some calls where another argument already has a date or time type, as in date_diff('day', DATE '2026-11-01', '2026-11-18'). Write a typed literal or cast the string, as in CAST(.order_day AS DATE)
The session time zone is UTC, and you cannot change it. A TIMESTAMP WITH TIME ZONE value does not keep the offset that it was written with. It is returned in UTC, and functions that read its parts, such as the day or the hour, read them in UTC. The functions that return the current date or time also use UTC.
Functions such as date_part, date_trunc, date_diff, and date_sub take the part as a string, such as 'year', 'quarter', 'month', 'week', 'day', 'hour', 'minute', 'second', 'millisecond', or 'microsecond'. All four also accept 'decade', 'century', and 'millennium'. The date_part function also accepts 'era', 'dow' (the day of the week, with Sunday as 0), and 'doy' (the day of the year). For ISO weeks, it accepts 'isodow' (the ISO day of the week, with Monday as 1 and Sunday as 7), 'isoyear', and 'yearweek'. It also accepts 'epoch' (seconds since 1970-01-01 00:00:00 UTC), 'julian', and 'timezone'. Part names are not case-sensitive, and plural and short forms such as 'days', 'd', and 'mon' also work.
Use + and - to add and subtract intervals. A DATE plus or minus an INTERVAL returns a TIMESTAMP. A DATE plus or minus an INTEGER returns the DATE that many days later or earlier. The difference of two DATE values is a number of days as a BIGINT. The difference of two TIMESTAMP values is an INTERVAL. To add a BIGINT number of days to a DATE, cast it to INTEGER first. When you add months or years and the day does not exist in the resulting month, the result is the last day of that month. For example, DATE '2026-01-31' + INTERVAL 1 MONTH returns 2026-02-28 00:00:00.
An INTERVAL keeps its months, days, and time of day separately, so INTERVAL 36 HOUR is not changed to 1 day and 12 hours. Hive tables and Iceberg tables cannot store INTERVAL values, so convert an interval before you write it to a table, for example to a number of seconds with date_part('epoch', .interval)
Topics
The following table lists the date and time functions and operators, with a link to the description of each one.
| Function | Description |
|---|---|
Returns the time between two timestamps as an interval in years, months, and days. |
|
Returns the current date and time minus an interval. |
|
Returns the century of a date, a timestamp, or an interval. |
|
Returns the current date in UTC. |
|
Returns the current time of day in UTC, without a time zone. |
|
Returns the current date and time in UTC, without a time zone. |
|
Adds an interval to a date, a timestamp, or a time. |
|
Counts how many times the span from one date or timestamp to another crosses the start of a unit, such as a month or an hour. |
|
Returns a part of a date, a time, a timestamp, or an interval, such as the year or the hour. |
|
Counts the whole units, such as whole months or whole hours, that fit in the span from one date or timestamp to another. |
|
Truncates a date, a timestamp, or an interval to the start of a part, such as the month or the hour. |
|
datediff |
Alias of date_diff. |
datepart |
Alias of date_part. |
datesub |
Alias of date_sub. |
datetrunc |
Alias of date_trunc. |
Returns the day of the month of a date or a timestamp, or the days part of an interval. |
|
Returns the day of the week of a date or a timestamp as an English word, such as |
|
dayofmonth |
Alias of day. |
Returns the day of the week as a number from 0 for Sunday to 6 for Saturday. |
|
Returns the day of the year, from 1 to 366, of a date or timestamp. |
|
Returns the number of days in the month of a date or timestamp. |
|
Returns the decade of a date or timestamp, which is the year divided by 10. |
|
Returns the number of seconds since 1970-01-01 00:00:00 UTC, or the length of an interval in seconds. |
|
Returns the number of milliseconds since 1970-01-01 00:00:00 UTC, or converts a number of milliseconds to a timestamp. |
|
Returns the number of nanoseconds since 1970-01-01 00:00:00 UTC, or the length of an interval in nanoseconds. |
|
Returns the number of microseconds since 1970-01-01 00:00:00 UTC, or the length of an interval in microseconds. |
|
Returns the era of a date or timestamp: 1 for AD and 0 for BC. |
|
Returns the current time of day with a time zone. |
|
Returns the current date and time with a time zone. |
|
Returns the hour, from 0 to 23, of a time or timestamp. |
|
Returns the ISO 8601 day of the week, from 1 for Monday to 7 for Sunday. |
|
Returns the ISO 8601 week-numbering year of a date or timestamp. |
|
Converts a date or timestamp to its Julian day number, with the time of day as a fraction. |
|
Returns the date of the final day in the month that contains a date or timestamp. |
|
Builds a date from a year, month, and day, from a struct of those parts, or from a number of days since 1970-01-01. |
|
Builds a time of day from an hour, a minute, and seconds. |
|
Builds a timestamp from its date and time parts, or from a number of microseconds since 1970-01-01 00:00:00. |
|
Converts a number of milliseconds since 1970-01-01 00:00:00 to a timestamp. |
|
Converts a number of nanoseconds since 1970-01-01 00:00:00 to a nanosecond-precision timestamp. |
|
Builds a timestamp with time zone from its date and time parts and an optional time zone, or from a number of microseconds since 1970-01-01 00:00:00 UTC. |
|
Returns the seconds and fractional seconds of a timestamp, time, or interval, in microseconds. |
|
Returns the millennium, counted from year 1, that a date or timestamp falls in, or the number of whole millennia in an interval. |
|
Returns the seconds and fractional seconds of a timestamp, time, or interval, in milliseconds. |
|
Returns the minute of a timestamp or time, or the minutes part of an interval. |
|
Returns the number of the month, from |
|
Returns the month of a date or timestamp as a full English word, such as |
|
Returns the seconds and fractional seconds of a timestamp, time, or interval, in nanoseconds. |
|
Rewrites an interval so that whole 24-hour periods become days and whole 30-day periods become months. |
|
now |
Alias of get_current_timestamp. |
Returns one row for each time zone name that you can use, with its abbreviation, current UTC offset, and daylight saving time flag. |
|
Returns the quarter of the year, from |
|
Returns the seconds part of a time, timestamp, or interval, without the fraction of a second. |
|
Formats a date or timestamp as a string by using format specifiers such as |
|
Parses a string into a timestamp by using a format string, and fails when the string does not match. |
|
Rounds a date, time, or timestamp down to the start of a fixed-width interval, such as 15 minutes or 1 week. |
|
Converts between an instant and the local time in a time zone, or returns the UTC offset of a value in seconds. |
|
Returns the hours part of the UTC offset of a time or timestamp. |
|
Returns the minutes part of the UTC offset of a time or timestamp. |
|
Returns an interval of a given number of centuries. |
|
Returns an interval of a given number of days. |
|
Returns an interval of a given number of decades. |
|
Returns an interval of a given number of hours. |
|
Returns an interval of a given number of microseconds. |
|
Returns an interval of a given number of millennia. |
|
Returns an interval of a given number of milliseconds, which can include a fraction of a millisecond. |
|
Returns an interval of a given number of minutes. |
|
Returns an interval of a given number of months. |
|
Returns an interval of a given number of quarters, where each quarter is three months. |
|
Returns an interval of a given number of seconds, which can include a fraction of a second. |
|
Returns the |
|
Returns an interval of a given number of weeks. |
|
Returns an interval of a given number of years. |
|
Returns the current date in UTC. |
|
transaction_timestamp |
Alias of get_current_timestamp. |
Parses a string into a timestamp by using a format string, and returns |
|
Returns the ISO 8601 week number of a date or timestamp. |
|
weekday |
Alias of dayofweek. |
weekofyear |
Alias of week. |
Returns the year of a date or timestamp, or the number of whole years in an interval. |
|
Returns the ISO 8601 year and week of a date or timestamp as one number in the form |