Shape / columns · All operations
Extract a part of a date
A variant of Parse a date or time
Take a component such as the year, month, weekday or hour out of a date or time as its own value.
Status
- In arcform
Runs as a SQL step
arcform carries it as a
sql:step today.
The DuckDB step
Take the year, month, weekday and hour out of a date
It reads the orders table the proofs share. Create it first:
CREATE TABLE orders AS SELECT * FROM (VALUES
(1, 'Alice Ng', 'north', DATE '2026-01-03', 120.00, 'widget', 'a|b', '{"channel":"web","items":[1,2]}'),
(2, 'alice ng', 'north', DATE '2026-01-05', 80.50, 'gadget', 'b', '{"channel":"shop","items":[3]}'),
(3, 'Bob Okafor', 'south', DATE '2026-01-05', 300.00, 'widget', 'a|c', '{"channel":"web","items":[4,5,6]}'),
(4, 'Carla Díaz', 'east', DATE '2026-01-09', NULL, 'gizmo', NULL, '{"channel":"web","items":[]}'),
(5, 'Bob Okafor', 'south', DATE '2026-01-12', 45.25, 'gadget', 'c', '{"channel":"phone","items":[7]}'),
(6, 'Dev Patel', 'west', DATE '2026-01-12', 510.00, 'widget', 'a', '{"channel":"web","items":[8,9]}'),
(7, 'Carla Diaz', 'east', DATE '2026-01-20', 99.99, 'gizmo', 'b|c', '{"channel":"shop","items":[10]}'),
(8, 'Dev Patel', 'west', DATE '2026-02-02', 510.00, 'widget', 'a', '{"channel":"web","items":[8,9]}'),
(9, 'Eve Larsen', NULL, DATE '2026-02-03', 15.00, 'gadget', NULL, '{"channel":"web","items":[11]}'),
(10, 'Alice Ng', 'north', DATE '2026-02-10', 220.00, 'gizmo', 'a|b|c', '{"channel":"phone","items":[12,13]}')
) t(order_id, customer, region, order_date, amount, product, tags, meta);Then run the statement:
CREATE TEMP TABLE result AS
SELECT order_id, year(order_date) AS yr, month(order_date) AS mo, dayname(order_date) AS weekday, quarter(order_date) AS qtr,
hour(TIMESTAMP '2026-02-10 14:30:00') AS hr
FROM orders;
SELECT * FROM result;
SELECT CASE WHEN ((SELECT [yr, mo, qtr, hr] FROM result WHERE order_id = 10) = [2026, 2, 1, 14] AND (SELECT weekday FROM result WHERE order_id = 10) = 'Tuesday' AND (SELECT weekday FROM result WHERE order_id = 1) = 'Saturday' AND (SELECT count(*) FILTER (WHERE mo = 1) FROM result) = 7) THEN 'as expected' ELSE error('year, month, weekday, quarter and hour were not taken out of the dates correctly') END AS verdict;- It needs nothing installed beyond DuckDB itself.
- The statement checks its own result and raises an error when it is wrong: “year, month, weekday, quarter and hour were not taken out of the dates correctly”.
- It passed on DuckDB
v2.0.0 (Cyanoptera) d54cbbe3df.
What other tools call it
Meridian's classification; an independent blind rating agreed on 95.7% of 324 rows (variant, version 3).
AWS Glue (1)
MonthNameread 2026-09-27Add a column with the month name taken from a date string
DuckDB (1)
Date Part Functions (family)read 2026-09-27The functions documented on the Date Part Functions page
Duckle (1)
Extract Partread 2026-09-25extract a date part
EasyMorph (1)
Make date/time columnsread 2026-09-27Derive columns of date and time attributes from a date column
Ibis (16)
Dateread 2026-09-27Date part of a timestamp
DayOfWeekIndexread 2026-09-27Day of the week of a date or timestamp, as a number
DayOfWeekNameread 2026-09-27Day of the week of a date or timestamp, as a name
ExtractDayread 2026-09-27Day of the month of a date or timestamp
ExtractDayOfYearread 2026-09-27Day of the year of a date or timestamp
ExtractHourread 2026-09-27Hour of a time or timestamp
ExtractIsoYearread 2026-09-27ISO year of a date or timestamp
ExtractMicrosecondread 2026-09-27Microsecond of a time or timestamp
ExtractMillisecondread 2026-09-27Millisecond of a time or timestamp
ExtractMinuteread 2026-09-27Minute of a time or timestamp
ExtractMonthread 2026-09-27Month of a date or timestamp
ExtractQuarterread 2026-09-27Quarter of a date or timestamp
ExtractSecondread 2026-09-27Second of a time or timestamp
ExtractWeekOfYearread 2026-09-27Week of the year of a date or timestamp
ExtractYearread 2026-09-27Year of a date or timestamp
Timeread 2026-09-27Time part of a timestamp
KNIME Analytics Platform (1)
Date&Time Part Extractorread 2026-09-27Extract fields such as year, month, day or hour from date&time columns
Polars (1)
SQL functions: Temporal (group)read 2026-09-273 functions: DATE_PART, EXTRACT, STRFTIME; SQL temporal functions
RapidMiner Studio (1)
Date to Numericalread 2026-09-27Convert a date column to a number: epoch offset or an extracted component such as month
Tableau Prep (2)
Convert Datesread 2026-09-27Convert a date field to its year, quarter, month, week, day, weekday name or month name
Custom Fiscal Yearread 2026-09-27Convert dates using a fiscal year that starts in a chosen month
Background
In PostgreSQL, the extract function retrieves a subfield, such as the year or the hour, from a date, time, timestamp or interval value.[1] In DuckDB, date_part('minute', TIMESTAMP '1992-09-20 20:38:40') returns 38, and the extract syntax is equivalent.[2]
When to use it
In DuckDB, dayofweek counts Sunday as 0 and Saturday as 6, while isodow counts Monday as 1 and Sunday as 7.[3] Pick one weekday numbering for a project and convert to it at the point of extraction. (Meridian's view)
In DuckDB, the milliseconds and microseconds parts count within the minute, so microsecond(TIMESTAMP '2021-08-03 11:59:44.123456') is 44123456.[3] In DuckDB, parts extracted from an infinite timestamp are NULL, because DuckDB has no infinite integer values.[3]
The method
DuckDB extracts every part as an integer except julian and epoch, which return DOUBLE values.[3] In DuckDB, date_part given a list of parts returns them together as a struct, such as {year: 1992, month: 9, day: 20}.[2] DuckDB's dayname and monthname return the English name of the weekday or month.[2]
ISO 8601's formal definition of week 01 is the week with the starting year's first Thursday in it.[4] DuckDB's isoyear starts on the Monday of the week containing 4 January, so isoyear(DATE '2022-01-01') is 2021.[3]
Sources
- [1]PostgreSQL: Documentation: 18: 9.9. Date/Time Functions and Operatorsdocumentation
- [2]Timestamp Functions – DuckDBdocumentation
- [3]Date Part Functions – DuckDBdocumentation
- [4]ISO 8601 - Wikipediasecondary source