In SQLite, dates are text like '2026-03-15'. strftime('%Y-%m', order_date) turns them into months for grouping.
julianday(end) − julianday(start) gives the number of days between two dates. Other databases use DATE_TRUNC or DATEDIFF, but the idea is the same.
Worked example
How many orders were placed each month?
SELECT strftime('%Y-%m', order_date) AS month, COUNT(*) AS orders
FROM orders
GROUP BY month
ORDER BY month;| month | orders |
|---|---|
| 2026-01 | 5 |
| 2026-02 | 3 |
| 2026-03 | 5 |
| 2026-04 | 5 |
| 2026-05 | 6 |
| 2026-06 | 9 |
| 2026-07 | 8 |
| 2026-08 | 8 |
| 2026-09 | 6 |
Common mistakes
- Grouping by the full date when you meant the month.
- Comparing dates stored in different formats.