Full answer
sql
SELECT strftime('%w', '2026-03-01') AS sun_w, strftime('%w', '2026-03-02') AS mon_w,
typeof(strftime('%w', '2026-03-01')) AS t;| sun_w | mon_w | t |
|---|---|---|
| 0 | 1 | text |
sql
SELECT EXTRACT(DOW FROM DATE '2026-03-01') AS sun_dow, EXTRACT(ISODOW FROM DATE '2026-03-01') AS sun_isodow,
EXTRACT(ISODOW FROM DATE '2026-03-02') AS mon_isodow;| sun_dow | sun_isodow | mon_isodow |
|---|---|---|
| 0 | 7 | 1 |
SQLite 3.46 also accepts %u (ISO, Monday = 1 to Sunday = 7), matching PostgreSQL's ISODOW:
sql
SELECT strftime('%u', '2026-03-01') AS sun_u, strftime('%u', '2026-03-02') AS mon_u;| sun_u | mon_u |
|---|---|
| 7 | 1 |
A filter such as strftime('%w', d) IN ('0', '6') selects weekends in SQLite. Note that strftime returns text, so compare with '0' and '6', or cast the result. Many off-by-one bugs come from mixing Sunday-first and Monday-first numbering across tools.
sql
SELECT strftime('%w', '2026-03-01') AS sun_w, strftime('%w', '2026-03-02') AS mon_w,
typeof(strftime('%w', '2026-03-01')) AS t;
SELECT strftime('%u', '2026-03-01') AS sun_u, strftime('%u', '2026-03-02') AS mon_u;Checked on SQLite 3.46.1, run twice with identical output. PostgreSQL results in the answer were checked on PostgreSQL 17.12.
Key points
- SQLite %w: 0 = Sunday
- PostgreSQL DOW: 0 = Sunday; ISODOW: 7 = Sunday
- SQLite %u gives ISO numbering
- strftime returns text, not numbers
Common mistakes
- Comparing strftime output to integers
- Assuming Monday = 0 or 1 without checking
Follow-ups
- How would you count orders per weekday?
- How would you compute ISO week numbers?
Tips
- Ask which week convention the business uses