DOW Versus ISODOW Numbering

EXTRACT(DOW) numbers Sunday as 0 through Saturday 6, while ISODOW follows ISO 8601 with Monday 1 through Sunday 7.

SqlData Integrity

Code

snippet
-- EXTRACT(DOW):周日=0 ... 周六=6(美式编号)
-- EXTRACT(ISODOW):周一=1 ... 周日=7(ISO 8601 编号)
SELECT
    d,
    EXTRACT(DOW    FROM d) AS dow_number,
    EXTRACT(ISODOW FROM d) AS isodow_number,
    TO_CHAR(d, 'Dy')       AS day_name
FROM (VALUES
    (DATE '2026-11-15'),  -- Sunday
    (DATE '2026-11-16'),  -- Monday
    (DATE '2026-11-21'),  -- Saturday
    (DATE '2026-11-22')   -- Sunday
) AS days(d);

-- 周末过滤:用 ISODOW IN (6, 7) 不依赖“周日是 0”的隐式约定
SELECT COUNT(*) AS weekend_days
FROM (VALUES (DATE '2026-11-15'), (DATE '2026-11-16')) AS days(d)
WHERE EXTRACT(ISODOW FROM d) IN (6, 7);

How the snippet works

The file runs SELECT statements, touching d.

What the statements actually assemble: a WHERE clause narrowing which rows one statement affects; COUNT aggregation.

Applying it

The d table is the working surface here.

Statements that matter

SELECT COUNT(*) AS weekend_days
FROM (VALUES (DATE '2026-11-15'), (DATE '2026-11-16')) AS days(d)
WHERE EXTRACT(ISODOW FROM d) IN (6, 7);
SELECT
    d,
    EXTRACT(DOW    FROM d) AS dow_number,
    EXTRACT(ISODOW FROM d) AS isodow_number,
    TO_CHAR(d, 'Dy')       AS day_name
FROM (VALUES
    (DATE '2026-11-15'),  -- Sunday
    (DATE '2026-11-16'),  -- Monday
    (DATE '2026-11-21'),  -- Saturday
    (DATE '2026-11-22')   -- Sunday
) AS days(d);

Interactive Tools for This Topic

FAQ

Which tables does the SQL touch?
The references are `d`.