Last active
January 28, 2018 00:32
-
-
Save palmerj/0c6948dd9590405269d88f340fdb5489 to your computer and use it in GitHub Desktop.
SQLite3 - Generate date time ranges using SQL recursive query
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DROP TABLE IF EXISTS date_ranges; | |
CREATE TEMP TABLE date_ranges (start_datetime DATETIME); | |
WITH RECURSIVE | |
date_ranges(start_datetime) AS ( | |
VALUES('2011-05-01 00:00:00') | |
UNION ALL | |
SELECT datetime(start_datetime, '+1 month') | |
FROM date_ranges WHERE start_datetime < datetime('now', '-1 month') | |
) | |
SELECT start_datetime, datetime(start_datetime, '+1 month') AS end_datetime | |
FROM date_ranges; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment