Search Shortcut cmd + k | ctrl + k

- Installation
- Documentation

- Getting Started
- Connect

- Overview
- Concurrency

- Data Import

- Overview
- Data Sources
- CSV Files

- Overview
- Auto Detection
- Reading Faulty CSV Files
- Tips

- JSON Files

- Overview
- Creating JSON
- Loading JSON
- Writing JSON
- JSON Type
- JSON Functions
- Format Settings
- Installing and Loading
- SQL to / from JSON
- Caveats

- Multiple Files

- Overview
- Combining Schemas

- Parquet Files

- Overview
- Metadata
- Encryption
- Tips

- Partitioning

- Hive Partitioning
- Partitioned Writes

- Appender
- INSERT Statements

- Client APIs

- Overview
- C

- Overview
- Startup
- Configuration
- Query
- Data Chunks
- Vectors
- Values
- Types
- Prepared Statements
- Appender
- Table Functions
- Replacement Scans
- API Reference

- C++
- CLI

- Overview
- Arguments
- Dot Commands
- Output Formats
- Editing
- Autocomplete
- Syntax Highlighting

- Dart
- Go
- Java
- Julia
- Node.js (Neo)

- Overview

- Node.js

- Overview
- API Reference

- Python

- Overview
- Data Ingestion
- Conversion between DuckDB and Python
- DB API
- Relational API
- Function API
- Types API
- Expression API
- Spark API
- API Reference
- Known Python Issues

- R
- Rust
- Swift
- Wasm

- Overview
- Instantiation
- Data Ingestion
- Query
- Extensions

- ADBC
- ODBC

- Overview
- Linux Setup
- Windows Setup
- macOS Setup
- Configuration

- SQL

- Introduction
- Statements

- Overview
- ANALYZE
- ALTER TABLE
- ALTER VIEW
- ATTACH and DETACH
- CALL
- CHECKPOINT
- COMMENT ON
- COPY
- CREATE INDEX
- CREATE MACRO
- CREATE SCHEMA
- CREATE SECRET
- CREATE SEQUENCE
- CREATE TABLE
- CREATE VIEW
- CREATE TYPE
- DELETE
- DESCRIBE
- DROP
- EXPORT and IMPORT DATABASE
- INSERT
- LOAD / INSTALL
- PIVOT
- Profiling
- SELECT
- SET / RESET
- SET VARIABLE
- SUMMARIZE
- Transaction Management
- UNPIVOT
- UPDATE
- USE
- VACUUM

- Query Syntax

- SELECT
- FROM and JOIN
- WHERE
- GROUP BY
- GROUPING SETS
- HAVING
- ORDER BY
- LIMIT and OFFSET
- SAMPLE
- Unnesting
- WITH
- WINDOW
- QUALIFY
- VALUES
- FILTER
- Set Operations
- Prepared Statements

- Data Types

- Overview
- Array
- Bitstring
- Blob
- Boolean
- Date
- Enum
- Interval
- List
- Literal Types
- Map
- NULL Values
- Numeric
- Struct
- Text
- Time
- Timestamp
- Time Zones
- Union
- Typecasting

- Expressions

- Overview
- CASE Statement
- Casting
- Collations
- Comparisons
- IN Operator
- Logical Operators
- Star Expression
- Subqueries

- Functions

- Overview
- Aggregate Functions
- Array Functions
- Bitstring Functions
- Blob Functions
- Date Format Functions
- Date Functions
- Date Part Functions
- Enum Functions
- Interval Functions
- Lambda Functions
- List Functions
- Map Functions
- Nested Functions
- Numeric Functions
- Pattern Matching
- Regular Expressions
- Struct Functions
- Text Functions
- Time Functions
- Timestamp Functions
- Timestamp with Time Zone Functions
- Union Functions
- Utility Functions
- Window Functions

- Constraints
- Indexes
- Meta Queries

- Information Schema
- Metadata Functions

- DuckDB's SQL Dialect

- Overview
- Indexing
- Friendly SQL
- Keywords and Identifiers
- Order Preservation
- PostgreSQL Compatibility

- Samples

- Configuration

- Overview
- Pragmas
- Secrets Manager

- Extensions

- Overview
- Core Extensions
- Community Extensions
- Working with Extensions
- Versioning of Extensions
- Arrow
- AutoComplete
- AWS
- Azure
- Delta
- Excel
- Full Text Search
- httpfs (HTTP and S3)

- Overview
- HTTP(S) Support
- Hugging Face
- S3 API Support
- Legacy Authentication Scheme for S3 API

- Iceberg
- ICU
- inet
- jemalloc
- MySQL
- PostgreSQL
- Spatial

- Overview
- Function Reference
- R-Tree Indexes
- GDAL Integration

- SQLite
- Substrait
- TPC-DS
- TPC-H
- VSS

- Guides

- Overview
- Data Viewers

- Tableau
- CLI Charting with YouPlot

- Database Integration

- Overview
- MySQL Import
- PostgreSQL Import
- SQLite Import

- File Formats

- Overview
- CSV Import
- CSV Export
- Directly Reading Files
- Excel Import
- Excel Export
- JSON Import
- JSON Export
- Parquet Import
- Parquet Export
- Querying Parquet Files

- Network and Cloud Storage

- Overview
- HTTP Parquet Import
- S3 Parquet Import
- S3 Parquet Export
- S3 Iceberg Import
- S3 Express One
- GCS Import
- Cloudflare R2 Import
- DuckDB over HTTPS / S3

- Meta Queries

- Describe Table
- EXPLAIN: Inspect Query Plans
- EXPLAIN ANALYZE: Profile Queries
- List Tables
- Summarize
- DuckDB Environment

- ODBC

- ODBC Guide

- Performance

- Overview
- Environment
- Import
- Schema
- Indexing
- Join Operations
- File Formats
- How to Tune Workloads
- My Workload Is Slow
- Benchmarks

- Python

- Installation
- Executing SQL
- Jupyter Notebooks
- SQL on Pandas
- Import from Pandas
- Export to Pandas
- Import from Numpy
- Export to Numpy
- SQL on Arrow
- Import from Arrow
- Export to Arrow
- Relational API on Pandas
- Multiple Python Threads
- Integration with Ibis
- Integration with Polars
- Using fsspec Filesystems

- SQL Editors

- DBeaver SQL IDE

- SQL Features

- AsOf Join
- Full-Text Search
- query and query_table Functions

- Snippets

- Create Synthetic Data
- Sharing Macros

- Glossary of Terms
- Browse Offline

- Operations Manual

- Overview
- Limits
- Non-Deterministic Behavior
- Embedding DuckDB
- DuckDB's Footprint

- Files Created by DuckDB
- Gitignore for DuckDB
- Reclaiming Space

- Securing DuckDB

- Overview
- Securing Extensions

- Development

- DuckDB Repositories
- Testing

- Overview
- sqllogictest Introduction
- Writing Tests
- Debugging
- Result Verification
- Persistent Testing
- Loops
- Multiple Connections
- Catch

- Profiling
- Release Calendar
- Building

- Overview
- Build Instructions
- Build Configuration
- Building Extensions
- Platforms
- Troubleshooting

- Benchmark Suite

- Internals

- Overview
- Storage Versions and Format
- Execution Format
- Pivot

- Sitemap
- Why DuckDB
- Media
- FAQ
- Code of Conduct
- Live Demo

Date Part Functions

The `date_part` and `date_diff` and `date_trunc` functions can be used to manipulate the fields of temporal types such as `DATE` and `TIMESTAMP`. The fields are specified as strings that contain the part name of the field.

Below is a full list of all available date part specifiers. The examples are the corresponding parts of the timestamp `2021-08-03 11:59:44.123456`.

## Part Specifiers Usable as Date Part Specifiers and in Intervals

Specifier | Description | Synonyms | Example
--- | --- | --- | ---
`'century'` | Gregorian century | `'cent'`, `'centuries'`, `'c'` | `21`
`'day'` | Gregorian day | `'days'`, `'d'`, `'dayofmonth'` | `3`
`'decade'` | Gregorian decade | `'dec'`, `'decades'`, `'decs'` | `202`
`'hour'` | Hours | `'hr'`, `'hours'`, `'hrs'`, `'h'` | `11`
`'microseconds'` | Sub-minute microseconds | `'microsecond'`, `'us'`, `'usec'`, `'usecs'`, `'usecond'`, `'useconds'` | `44123456`
`'millennium'` | Gregorian millennium | `'mil'`, `'millenniums'`, `'millenia'`, `'mils'`, `'millenium'` | `3`
`'milliseconds'` | Sub-minute milliseconds | `'millisecond'`, `'ms'`, `'msec'`, `'msecs'`, `'msecond'`, `'mseconds'` | `44123`
`'minute'` | Minutes | `'min'`, `'minutes'`, `'mins'`, `'m'` | `59`
`'month'` | Gregorian month | `'mon'`, `'months'`, `'mons'` | `8`
`'quarter'` | Quarter of the year (1-4) | `'quarters'` | `3`
`'second'` | Seconds | `'sec'`, `'seconds'`, `'secs'`, `'s'` | `44`
`'year'` | Gregorian year | `'yr'`, `'y'`, `'years'`, `'yrs'` | `2021`

## Part Specifiers Only Usable as Date Part Specifiers

Specifier | Description | Synonyms | Example
--- | --- | --- | ---
`'dayofweek'` | Day of the week (Sunday = 0, Saturday = 6) | `'weekday'`, `'dow'` | `2`
`'dayofyear'` | Day of the year (1-365/366) | `'doy'` | `215`
`'epoch'` | Seconds since 1970-01-01 |  | `1627991984`
`'era'` | Gregorian era (CE/AD, BCE/BC) |  | `1`
`'isodow'` | ISO day of the week (Monday = 1, Sunday = 7) |  | `2`
`'isoyear'` | ISO Year number (Starts on Monday of week containing Jan 4th) |  | `2021`
`'timezone_hour'` | Time zone offset hour portion |  | `0`
`'timezone_minute'` | Time zone offset minute portion |  | `0`
`'timezone'` | Time zone offset in seconds |  | `0`
`'week'` | Week number | `'weeks'`, `'w'` | `31`
`'yearweek'` | ISO year and week number in `YYYYWW` format |  | `202131`

Note that the time zone parts are all zero unless a time zone plugin such as ICU has been installed to support `TIMESTAMP WITH TIME ZONE`.

## Part Functions

There are dedicated extraction functions to get certain subfields:

Name | Description
--- | ---
`century(date)` | Century.
`day(date)` | Day.
`dayofmonth(date)` | Day (synonym).
`dayofweek(date)` | Numeric weekday (Sunday = 0, Saturday = 6).
`dayofyear(date)` | Day of the year (starts from 1, i.e., January 1 = 1).
`decade(date)` | Decade (year / 10).
`epoch(date)` | Seconds since 1970-01-01.
`era(date)` | Calendar era.
`hour(date)` | Hours.
`isodow(date)` | Numeric ISO weekday (Monday = 1, Sunday = 7).
`isoyear(date)` | ISO Year number (Starts on Monday of week containing Jan 4th).
`microsecond(date)` | Sub-minute microseconds.
`millennium(date)` | Millennium.
`millisecond(date)` | Sub-minute milliseconds.
`minute(date)` | Minutes.
`month(date)` | Month.
`quarter(date)` | Quarter.
`second(date)` | Seconds.
`timezone_hour(date)` | Time zone offset hour portion.
`timezone_minute(date)` | Time zone offset minutes portion.
`timezone(date)` | Time Zone offset in minutes.
`week(date)` | ISO Week.
`weekday(date)` | Numeric weekday synonym (Sunday = 0, Saturday = 6).
`weekofyear(date)` | ISO Week (synonym).
`year(date)` | Year.
`yearweek(date)` | `BIGINT` of combined ISO Year number and 2-digit version of ISO Week number.

#### `century(date)`

Description | Century.
Example | `century(date '1992-02-15')`
Result | `20`

#### `day(date)`

Description | Day.
Example | `day(date '1992-02-15')`
Result | `15`

#### `dayofmonth(date)`

Description | Day (synonym).
Example | `dayofmonth(date '1992-02-15')`
Result | `15`

#### `dayofweek(date)`

Description | Numeric weekday (Sunday = 0, Saturday = 6).
Example | `dayofweek(date '1992-02-15')`
Result | `6`

#### `dayofyear(date)`

Description | Day of the year (starts from 1, i.e., January 1 = 1).
Example | `dayofyear(date '1992-02-15')`
Result | `46`

#### `decade(date)`

Description | Decade (year / 10).
Example | `decade(date '1992-02-15')`
Result | `199`

#### `epoch(date)`

Description | Seconds since 1970-01-01.
Example | `epoch(date '1992-02-15')`
Result | `698112000`

#### `era(date)`

Description | Calendar era.
Example | `era(date '0044-03-15 (BC)')`
Result | `0`

#### `hour(date)`

Description | Hours.
Example | `hour(timestamp '2021-08-03 11:59:44.123456')`
Result | `11`

#### `isodow(date)`

Description | Numeric ISO weekday (Monday = 1, Sunday = 7).
Example | `isodow(date '1992-02-15')`
Result | `6`

#### `isoyear(date)`

Description | ISO Year number (Starts on Monday of week containing Jan 4th).
Example | `isoyear(date '2022-01-01')`
Result | `2021`

#### `microsecond(date)`

Description | Sub-minute microseconds.
Example | `microsecond(timestamp '2021-08-03 11:59:44.123456')`
Result | `44123456`

#### `millennium(date)`

Description | Millennium.
Example | `millennium(date '1992-02-15')`
Result | `2`

#### `millisecond(date)`

Description | Sub-minute milliseconds.
Example | `millisecond(timestamp '2021-08-03 11:59:44.123456')`
Result | `44123`

#### `minute(date)`

Description | Minutes.
Example | `minute(timestamp '2021-08-03 11:59:44.123456')`
Result | `59`

#### `month(date)`

Description | Month.
Example | `month(date '1992-02-15')`
Result | `2`

#### `quarter(date)`

Description | Quarter.
Example | `quarter(date '1992-02-15')`
Result | `1`

#### `second(date)`

Description | Seconds.
Example | `second(timestamp '2021-08-03 11:59:44.123456')`
Result | `44`

#### `timezone_hour(date)`

Description | Time zone offset hour portion.
Example | `timezone_hour(date '1992-02-15')`
Result | `0`

#### `timezone_minute(date)`

Description | Time zone offset minutes portion.
Example | `timezone_minute(date '1992-02-15')`
Result | `0`

#### `timezone(date)`

Description | Time Zone offset in minutes.
Example | `timezone(date '1992-02-15')`
Result | `0`

#### `week(date)`

Description | ISO Week.
Example | `week(date '1992-02-15')`
Result | `7`

#### `weekday(date)`

Description | Numeric weekday synonym (Sunday = 0, Saturday = 6).
Example | `weekday(date '1992-02-15')`
Result | `6`

#### `weekofyear(date)`

Description | ISO Week (synonym).
Example | `weekofyear(date '1992-02-15')`
Result | `7`

#### `year(date)`

Description | Year.
Example | `year(date '1992-02-15')`
Result | `1992`

#### `yearweek(date)`

Description | `BIGINT` of combined ISO Year number and 2-digit version of ISO Week number.
Example | `yearweek(date '1992-02-15')`
Result | `199207`

##### About this page

- Report content issue
- Edit this page on GitHub