Before you start, you need
Extract parts or shift a date
A date can tell you the year someone joined or the day of their next check-up. First decide whether you need part of the date, or a completely new date.
In the course data, dates are written as year-month-day. For example, 2025-06-10 means 10 June 2025. This format is also called YYYY-MM-DD.
STRFTIME('%Y', joined_at) gets the year; '%Y' says which part we want to extract. DATE(joined_at, '+7 days') calculates seven days later; '+7 days' expresses the shift.
Both calculations can be shown in SELECT with an alias. The original date is kept and DATE takes the length of each month into account. We use SQLite syntax that works in the lab; other engines may write these functions differently.
SELECT STRFTIME('%Y', joined_at) AS year,
DATE(joined_at, '+7 days') AS review
FROM employees;See it in action
We want to schedule a check-up seven days after each employee's start date.
SELECT name,
joined_at,
DATE(joined_at, '+7 days') AS review
FROM employees;| name | joined_at | review |
|---|---|---|
| Claire Smith | 2021-02-15 | 2021-02-22 |
| Alex Reed | 2022-05-10 | 2022-05-17 |
| Beth Morgan | 2024-01-12 | 2024-01-19 |
| Charles Page | 2021-09-01 | 2021-09-08 |
| Diana Lane | 2023-03-20 | 2023-03-27 |
| Ernest Cole | 2024-06-02 | 2024-06-09 |
| Faith Rivers | 2022-11-18 | 2022-11-25 |
| Graham Newton | 2023-08-07 | 2023-08-14 |
- joined_at shows the starting point. DATE returns the date seven days later.
- The result lets you compare both dates next to each employee. The calculation handles changes of month: it does not just add 7 to the day in the text.
- If you only need the year, STRFTIME('%Y', joined_at) extracts it as text. That is the first practice task.
- Do not use a day/month/year format in these arguments. The course data already uses YYYY-MM-DD.
Practice with help
Getting things wrong is part of learning: you can run your query as many times as you like and nothing is lost. If you get stuck, open a hint (each one reveals a bit more) and save the solution for last.
Guided practice
Extract the year
Show name and STRFTIME('%Y', joined_at) as joined_year from employees.
Expected result: 10 rows with the columns name, joined_year, in that order. Row order does not matter.
View tables and data
Open this panel to see the full data.
You need part of the date, not a shifted date.
The format for extracting the year is %Y.
Apply STRFTIME to joined_at and use joined_year as the alias.
Solution explained
SELECT name, STRFTIME('%Y', joined_at) AS joined_year FROM employees;The year comes back as text, and joined_at stays unchanged.
Your turn
Solve this variation. Spot the part that has changed before you look for help.
Practice
Shift a date
Show name and DATE(joined_at, '+7 days') with the alias review_date from employees.
Expected result: 10 rows with the columns name, review_date, in that order. Row order does not matter.
View tables and data
Open this panel to see the full data.
The check-up date is a derived date, not an UPDATE.
Use the date function with a modifier expressed in days.
The modifier is '+7 days' and the alias is review_date.
Solution explained
SELECT name, DATE(joined_at, '+7 days') AS review_date FROM employees;The calculated date is seven days later, and the start date is not updated.
Key takeaways
- Course dates use YYYY-MM-DD.
- STRFTIME extracts a part.
- DATE calculates a new date.
- The saved date is preserved.
Go deeper
Going further: calculate the seven-day deadline and the month for three orders.
SELECT id, date, DATE(date, '+7 days') AS deadline, STRFTIME('%Y-%m', date) AS month FROM orders WHERE id IN (101, 102, 103) ORDER BY id;| id | date | deadline | month |
|---|---|---|---|
| 101 | 2025-05-02 | 2025-05-09 | 2025-05 |
| 102 | 2025-05-04 | 2025-05-11 | 2025-05 |
| 103 | 2025-05-10 | 2025-05-17 | 2025-05 |
- The deadline is calculated from each original date. The month is extracted as year-month text; the order and its date stay unchanged.
What date is seven days after 28 February in a leap year?
SELECT DATE('2024-02-28', '+7 days') AS review;| review |
|---|
| 2024-03-06 |
- The result is 6 March. DATE takes the length of the month into account, including 29 February.
Going further with SQLite: download and run it
Dates are YYYY-MM-DD. Compare the extracted year with the shifted date. DATE handles changes of month and leap years; the file also checks a deadline and a month extracted from orders.
Download the script with the database and ready-made queries. Open an empty SQLite database and import the script. In sqlite3 you can use .read functions-date-sqlite.sql. To run it again, import the file into another empty database.