SQL date() and strftime()
Work with dates in SQLite.
Syntax
date('now') date(d, '+30 days') strftime('%Y-%m', d)
SQLite stores dates as ISO text ('2025-06-14'). date() calculates new dates, strftime() extracts parts: %Y year, %m month, %d day, %w weekday (0 = Sunday).
Example
Query (on the shop database used in the SQL course)
SELECT order_date, strftime('%Y-%m', order_date) AS month, strftime('%w', order_date) AS weekday, date(order_date, '+14 days') AS due FROM orders LIMIT 4;
Result
| order_date | month | weekday | due |
|---|---|---|---|
| 2025-06-10 | 2025-06 | 2 | 2025-06-24 |
| 2025-05-17 | 2025-05 | 6 | 2025-05-31 |
| 2025-03-25 | 2025-03 | 2 | 2025-04-08 |
| 2025-10-26 | 2025-10 | 0 | 2025-11-09 |
4 rows
Good to know. PostgreSQL: CURRENT_DATE, d + INTERVAL '14 days', EXTRACT(MONTH FROM d), to_char(d, 'YYYY-MM').
Related
Learn it step by step in the free lesson Functions: Text, Numbers, Dates & CASE, with exercises that check your queries.