# Generate a range of dates

Acquire / generate

A variant of [Generate rows](https://meridian.online/operations/generate-rows).

Emit one row per date or timestamp between a start and an end at a chosen grain.

Page: <https://meridian.online/operations/generate-rows/generate-a-range-of-dates>

## Status

Runs as a SQL step.

arcform carries it as a `sql:` step today.

## The DuckDB step

emit a row for each day, week, month and hour between two bounds

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 spans AS
SELECT (SELECT list(d::DATE ORDER BY d) FROM generate_series(DATE '2026-01-01', DATE '2026-01-04', INTERVAL 1 DAY) t(d)) AS days,
       (SELECT list(d::DATE ORDER BY d) FROM generate_series(DATE '2026-01-05', DATE '2026-01-26', INTERVAL 1 WEEK) t(d)) AS weeks,
       (SELECT list(d::DATE ORDER BY d) FROM generate_series(DATE '2026-01-01', DATE '2026-04-01', INTERVAL 1 MONTH) t(d)) AS months,
       (SELECT list(d ORDER BY d) FROM generate_series(TIMESTAMP '2026-01-01 22:00', TIMESTAMP '2026-01-02 01:00', INTERVAL 1 HOUR) t(d)) AS hours;
-- a spine joined to the orders keeps the days that have none
CREATE TEMP TABLE result AS
SELECT s.day, count(o.order_id) AS orders
FROM (SELECT d::DATE AS day FROM generate_series(DATE '2026-01-03', DATE '2026-01-06', INTERVAL 1 DAY) t(d)) s
LEFT JOIN orders o ON o.order_date = s.day GROUP BY s.day;
SELECT * FROM spans; SELECT * FROM result ORDER BY day;
SELECT CASE WHEN ((SELECT len(days) = 4 AND len(weeks) = 4 AND weeks[4] = DATE '2026-01-26' AND months = [DATE '2026-01-01', DATE '2026-02-01', DATE '2026-03-01', DATE '2026-04-01'] AND len(hours) = 4 AND hours[4] = TIMESTAMP '2026-01-02 01:00' FROM spans) AND (SELECT list(orders ORDER BY day) FROM result) = [1, 0, 2, 0]) THEN 'as expected' ELSE error('the spine did not give 4 days, 4 weeks, 4 months and 4 hours, or keep the days with no order') END AS verdict;
```

It needs nothing installed beyond DuckDB itself.

## What other tools call it

Meridian's classification; an independent blind rating agreed on 95.7% of 324 rows (variant, version 3).

- Bruin: [`bruin.date_spine(datepart, start_date, end_date)`](https://getbruin.com/docs/bruin/assets/templating/macros.html) (read 2026-09-27)
- dbt-utils: [`date_spine`](https://raw.githubusercontent.com/dbt-labs/dbt-utils/main/README.md) (read 2026-09-27)
- EasyMorph: [`Calendar`](https://help.easymorph.com/doku.php?id=transformations:calendar) (read 2026-09-27)
- Ibis: [`TimestampRange`](https://github.com/ibis-project/ibis/blob/05d2b293344e86cb41c1a426071734f7e270335a/ibis/expr/operations/arrays.py) (read 2026-09-27)
- KNIME Analytics Platform: [`Date&Time Range Creator`](https://api.hub.knime.com/nodes/*Pn411WnBcRXagLfL?details=full) (read 2026-09-27)
- SQLMesh: [`@DATE_SPINE`](https://github.com/SQLMesh/sqlmesh/blob/23b237cea7218cc8f338b89c14f0957394a0003b/docs/concepts/macros/sqlmesh_macros.md) (read 2026-09-27)
