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:

SQL
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:

SQL
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-27

    Add a column with the month name taken from a date string

DuckDB (1)
Duckle (1)
EasyMorph (1)
Ibis (16)
KNIME Analytics Platform (1)
Polars (1)
RapidMiner Studio (1)
  • Date to Numericalread 2026-09-27

    Convert a date column to a number: epoch offset or an extracted component such as month

Tableau Prep (2)
  • Convert Datesread 2026-09-27

    Convert a date field to its year, quarter, month, week, day, weekday name or month name

  • Custom Fiscal Yearread 2026-09-27

    Convert 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]