SQL date practice: 7 exercises in PostgreSQL and SQLite
Updated · Tested on PostgreSQL 18.6 and SQLite 3.54.1 (results generated , re-checked on every release)
Seven exercises on dates, where PostgreSQL and SQLite differ most: filtering by date, pulling out the year and month, adding days, days between dates and the day of the week. Every answer is given in both dialects.
Write each query, press Check answer and get told right away whether your result matches. Stuck? Take a hint, or open the answer. New to the topic? Read the SQL date functions in PostgreSQL and SQLite guide first.
The tables
- pets (id, name, species, breed, age, weight_kg, adopted, arrived_on)
- adoption_requests (id, pet_name, email, phone, requested_on, budget)
- customers (id, name, city, joined_on)
- menu_items (id, name, category, price, vegetarian)
- orders (id, customer_id, ordered_on, status)
- order_items (order_id, item_id, quantity)
- staff (id, name, role, city, manager_id, hired_on)
- users (id, signed_up_on, country, source)
- plays (id, user_id, played_on, minutes, device)
- subscriptions (user_id, started_on, plan, cancelled_on)
- 1
Which pets arrived in 2026, that is on or after
'2026-01-01'? Show name and arrived_on.From the lesson Working with dates · Paws & Whiskers Shelter
Write your query here…Show the answerHide the answer
Answer (PostgreSQL and SQLite)
SELECT name, arrived_on FROM pets WHERE arrived_on >= '2026-01-01';Expected result (both engines): first 8 of 9 rows
name arrived_on Biscuit 2026-01-14 Luna 2026-02-03 Waffles 2026-03-11 Pepper 2026-04-19 Clover 2026-02-27 Maple 2026-05-01 Kiwi 2026-01-29 Bean 2026-06-12 - 2
Show each pet's name and the year it arrived as arrival_year.
From the lesson Working with dates · Paws & Whiskers Shelter
Write your query here…Show the answerHide the answer
Answer in SQLite
SELECT name, strftime('%Y', arrived_on) AS arrival_year FROM pets;In PostgreSQL
SELECT name, EXTRACT(YEAR FROM arrived_on) AS arrival_year FROM pets;Expected result (SQLite): first 8 of 20 rows
name arrival_year Biscuit 2026 Mochi 2025 Pickles 2025 Luna 2026 Waffles 2026 Bruno 2025 Pepper 2026 Noodle 2025 - 3
Show each pet's name and the month it arrived (like
2026-03) as arrival_month.From the lesson Working with dates · Paws & Whiskers Shelter
Write your query here…Show the answerHide the answer
Answer in SQLite
SELECT name, strftime('%Y-%m', arrived_on) AS arrival_month FROM pets;In PostgreSQL
SELECT name, to_char(arrived_on, 'YYYY-MM') AS arrival_month FROM pets;Expected result (both engines): first 8 of 20 rows
name arrival_month Biscuit 2026-01 Mochi 2025-11 Pickles 2025-09 Luna 2026-02 Waffles 2026-03 Bruno 2025-06 Pepper 2026-04 Noodle 2025-12 - 4
Every new pet sees the vet 14 days after arriving. Show name and that date as checkup_on.
From the lesson Date maths · Paws & Whiskers Shelter
Write your query here…Show the answerHide the answer
Answer in SQLite
SELECT name, date(arrived_on, '+14 days') AS checkup_on FROM pets;In PostgreSQL
SELECT name, arrived_on + 14 AS checkup_on FROM pets;Expected result (both engines): first 8 of 20 rows
name checkup_on Biscuit 2026-01-28 Mochi 2025-11-16 Pickles 2025-10-05 Luna 2026-02-17 Waffles 2026-03-25 Bruno 2025-07-14 Pepper 2026-05-03 Noodle 2025-12-22 - 5
How many days had each pet been at the shelter on 2026-11-17? Show name and days_here.
From the lesson Date maths · Paws & Whiskers Shelter
Write your query here…Show the answerHide the answer
Answer in SQLite
SELECT name, julianday('2026-11-17') - julianday(arrived_on) AS days_here FROM pets;In PostgreSQL
SELECT name, DATE '2026-11-17' - arrived_on AS days_here FROM pets;Expected result (both engines): first 8 of 20 rows
name days_here Biscuit 307 Mochi 380 Pickles 422 Luna 287 Waffles 251 Bruno 505 Pepper 212 Noodle 344 - 6
Which Rocket Pizza orders were placed on a Sunday? Show order id and ordered_on.
From the lesson Date maths · Rocket Pizza
Write your query here…Show the answerHide the answer
Answer in SQLite
SELECT id, ordered_on FROM orders WHERE strftime('%w', ordered_on) = '0';In PostgreSQL
SELECT id, ordered_on FROM orders WHERE EXTRACT(DOW FROM ordered_on) = 0;Expected result (both engines): 6 rows
id ordered_on 1 2026-03-01 2 2026-03-01 8 2026-03-08 13 2026-03-15 16 2026-03-22 17 2026-03-22 - 7
How many Streamly users signed up in February 2026? Use a half-open range on
signed_up_on(no function on the column, no BETWEEN). Return one number.From the lesson Index-friendly filters · Streamly
Write your query here…Show the answerHide the answer
Answer (PostgreSQL and SQLite)
SELECT COUNT(*) FROM users WHERE signed_up_on >= '2026-02-01' AND signed_up_on < '2026-03-01';Expected result (SQLite): 1 row
COUNT(*) 100
The lessons have more like these
Each lesson teaches the idea step by step first, then gives you exercises with instant feedback and a daily streak.
- Working with dates4 more exercises · sqlstreak Pro
- Date maths5 more exercises · sqlstreak Pro
- Index-friendly filters4 more exercises · sqlstreak Pro
More practice sets
Check your level
The free SQL test takes about 10 minutes and tells you which lesson to start with.