Generate date range in SQLite

-- recursive CTE to get a range of dates

-- #################
-- SQLite compatible
-- #################

WITH dates AS (
  SELECT '2025-01-01' AS date
  UNION ALL
  SELECT DATE(date, '+1 days') 
  FROM dates 
  WHERE date < '2025-01-31'
)


SELECT * FROM dates;


/*
Output:

| date       |
| ---------- |
| 2025-01-01 |
| 2025-01-02 |
| 2025-01-03 |
| 2025-01-04 |
| 2025-01-05 |
...
| 2025-01-30 |
| 2025-01-31 |

*/

Send a Comment

Your email address will not be published.