Working with Dates
Dates are everywhere in real data. SQLite stores dates as text in 'YYYY-MM-DD' format.
Get today's date:
Extract parts of a date with strftime(): strftime('%Y', hire_date) -- year: '2024' strftime('%m', hire_date) -- month: '03' strftime('%d', hire_date) -- day: '15'
Calculate days between dates:
Filter by date ranges:
Date math with date(): date('now', '-30 days') -- 30 days ago date('now', '+1 year') -- 1 year from now
Check your understanding
Which SQLite function extracts the year from a date?
Examples run on the employees sample database. Open any of them in the playground to experiment.