So far we compared dates as whole YYYY-MM-DD strings. SQLite also has date functions. The most useful one is strftime(format, date), which extracts a part of a date:
Loading data...
↗️
Loading editor...
↶
↷
%Y is the 4-digit year, %m the 2-digit month and %d the 2-digit day. Notice that the results are text: '2022', not the number 2022.
That makes it easy to filter on a single part of the date, whatever the day or month:
↗️
Loading editor...
↶
↷
Other databases
strftime is specific to SQLite. PostgreSQL uses EXTRACT(YEAR FROM date) and MySQL also has YEAR(date). The idea is identical, only the name changes.