How can I retrieve all dates between \'2015-10-02\' to \'2015-11-02\' in SQLite? (String type) Result will be like:
\'2015-10-03\'
\'2015-10-04\'
\'2015-10-0
This is not possible without a recursive common table expression, which was introduced in SQLite 3.8.3:
WITH RECURSIVE dates(date) AS (
VALUES('2015-10-03')
UNION ALL
SELECT date(date, '+1 day')
FROM dates
WHERE date < '2015-11-01'
)
SELECT date FROM dates;
If your date column is already a date type with the format YYYY-MM-DD
then you can use the following query:
SELECT date_field AS Date, COUNT(date_field)
FROM table
WHERE (date_field BETWEEN '2015-10-02' AND '2015-11-02')
GROUP BY date_field
If the date column is actually a string, then you can use the strftime()
function:
SELECT date_field AS Date, COUNT(date_field)
FROM table
WHERE strftime('%Y-%m-%d', date_field) BETWEEN '2015-10-02' AND '2015-11-02'
GROUP BY date_field