Search Shortcut cmd + k | ctrl + k
- Installation
- Guides
- Overview
- SQL Features
- Data Import & Export
- CSV Import
- CSV Export
- Parquet Import
- Parquet Export
- Query Parquet
- HTTP Parquet Import
- S3 Parquet Import
- S3 Parquet Export
- JSON Import
- JSON Export
- Excel Import
- Excel Export
- SQLite Import
- Postgres Import
- Meta Queries
- Python
- Install
- Execute SQL
- Jupyter Notebooks
- SQL on Pandas
- Import From Pandas
- Export To Pandas
- SQL on Arrow
- Import From Arrow
- Export To Arrow
- Relational API on Pandas
- Multiple Python Threads
- DuckDB with Ibis
- DuckDB with Fugue
- DuckDB with Polars
- DuckDB with Vaex
- DuckDB with DataFusion
- DuckDB with fsspec filesystems
- SQL Editors
- Data Viewers
- Documentation
- Connect
- Data Import
- Overview
- CSV Files
- JSON Files
- Multiple Files
- Parquet Files
- Partitioning
- Appender
- Insert Statements
- Client APIs
- Overview
- C
- Overview
- Startup
- Configure
- Query
- Data Chunks
- Values
- Types
- Prepared Statements
- Appender
- Table Functions
- Replacement Scans
- API Reference
- C++
- CLI
- Java
- Julia
- Node.js
- ODBC
- Python
- Overview
- Data Ingestion
- Result Conversion
- DB API
- Relational API
- Function API
- Types API
- API Reference
- R
- Rust
- Scala
- Swift
- Wasm
- SQL
- Introduction
- Statements
- Overview
- Alter Table
- Attach/Detach
- Call
- Checkpoint
- Copy
- Create Macro
- Create Schema
- Create Sequence
- Create Table
- Create View
- Delete
- Drop
- Export
- Insert
- Pivot
- Select
- Set/Reset
- Unpivot
- Update
- Use
- Vacuum
- Query Syntax
- SELECT
- FROM & JOIN
- WHERE
- GROUP BY
- GROUPING SETS
- HAVING
- ORDER BY
- LIMIT
- SAMPLE
- UNNEST
- WITH
- WINDOW
- QUALIFY
- VALUES
- FILTER
- Set Operations
- Data Types
- Overview
- Bitstring
- Blob
- Boolean
- Date
- Enum
- Interval
- List
- Map
- NULL Values
- Numeric
- Struct
- Text
- Timestamp
- Union
- Expressions
- Functions
- Overview
- Bitstring Functions
- Blob Functions
- Date Format Functions
- Date Functions
- Date Part Functions
- Enum Functions
- Interval Functions
- Nested Functions
- Numeric Functions
- Pattern Matching
- Text Functions
- Time Functions
- Timestamp Functions
- Timestamp With Time Zone Functions
- Utility Functions
- Aggregates
- Configuration
- Constraints
- Indexes
- Information Schema
- Metadata Functions
- Pragmas
- Samples
- Window Functions
- Extensions
- Sitemap
- Why DuckDB
- Media
- FAQ
- Code of Conduct
- Live Demo
Documentation
/ SQL
/ Functions
Interval Functions
This section describes functions and operators for examining and manipulating INTERVAL
values.
Interval Operators
The table below shows the available mathematical operators for INTERVAL
types.
Operator | Description | Example | Result |
---|---|---|---|
+ |
addition of an INTERVAL |
INTERVAL 1 HOUR + INTERVAL 5 HOUR |
INTERVAL 6 HOUR |
+ |
addition to a DATE |
DATE '1992-03-22' + INTERVAL 5 DAY |
1992-03-27 |
+ |
addition to a TIMESTAMP |
TIMESTAMP '1992-03-22 01:02:03' + INTERVAL 5 DAY |
1992-03-27 01:02:03 |
+ |
addition to a TIME |
TIME '01:02:03' + INTERVAL 5 HOUR |
06:02:03 |
- |
subtraction of an INTERVAL |
INTERVAL 5 HOUR - INTERVAL 1 HOUR |
INTERVAL 4 HOUR |
- |
subtraction from a DATE |
DATE '1992-03-27' - INTERVAL 5 DAY |
1992-03-22 |
- |
subtraction from a TIMESTAMP |
TIMESTAMP '1992-03-27 01:02:03' - INTERVAL 5 DAY |
1992-03-22 01:02:03 |
- |
subtraction from a TIME |
TIME '06:02:03' - INTERVAL 5 HOUR |
01:02:03 |
Interval Functions
The table below shows the available scalar functions for INTERVAL
types.
Function | Description | Example | Result |
---|---|---|---|
date_part( part , interval ) |
Get subfield (equivalent to extract) | date_part('year', INTERVAL '14 months') |
1 |
datepart( part , interval ) |
Alias of date_part. Get subfield (equivalent to extract) | datepart('year', INTERVAL '14 months') |
1 |
extract( part from interval ) |
Get subfield from a date | extract('month' FROM INTERVAL '14 months') |
2 |
to_days( integer ) |
Construct a day interval | to_days(5) |
INTERVAL 5 DAY |
to_hours( integer ) |
Construct a hour interval | to_hours(5) |
INTERVAL 5 HOUR |
to_microseconds( integer ) |
Construct a microsecond interval | to_microseconds(5) |
INTERVAL 5 MICROSECOND |
to_milliseconds( integer ) |
Construct a millisecond interval | to_milliseconds(5) |
INTERVAL 5 MILLISECOND |
to_minutes( integer ) |
Construct a minute interval | to_minutes(5) |
INTERVAL 5 MINUTE |
to_months( integer ) |
Construct a month interval | to_months(5) |
INTERVAL 5 MONTH |
to_seconds( integer ) |
Construct a second interval | to_seconds(5) |
INTERVAL 5 SECOND |
to_years( integer ) |
Construct a year interval | to_years(5) |
INTERVAL 5 YEAR |
Only the documented date parts are defined for intervals.