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.

Answers are checked on the engine you pick.
The tables

Paws & Whiskers Shelter

  • pets (id, name, species, breed, age, weight_kg, adopted, arrived_on)
  • adoption_requests (id, pet_name, email, phone, requested_on, budget)

Rocket Pizza

  • 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)

Streamly

  • users (id, signed_up_on, country, source)
  • plays (id, user_id, played_on, minutes, device)
  • subscriptions (user_id, started_on, plan, cancelled_on)
  1. 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 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

    namearrived_on
    Biscuit2026-01-14
    Luna2026-02-03
    Waffles2026-03-11
    Pepper2026-04-19
    Clover2026-02-27
    Maple2026-05-01
    Kiwi2026-01-29
    Bean2026-06-12
  2. 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 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

    namearrival_year
    Biscuit2026
    Mochi2025
    Pickles2025
    Luna2026
    Waffles2026
    Bruno2025
    Pepper2026
    Noodle2025
  3. 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 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

    namearrival_month
    Biscuit2026-01
    Mochi2025-11
    Pickles2025-09
    Luna2026-02
    Waffles2026-03
    Bruno2025-06
    Pepper2026-04
    Noodle2025-12
  4. 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 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

    namecheckup_on
    Biscuit2026-01-28
    Mochi2025-11-16
    Pickles2025-10-05
    Luna2026-02-17
    Waffles2026-03-25
    Bruno2025-07-14
    Pepper2026-05-03
    Noodle2025-12-22
  5. 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 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

    namedays_here
    Biscuit307
    Mochi380
    Pickles422
    Luna287
    Waffles251
    Bruno505
    Pepper212
    Noodle344
  6. 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 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

    idordered_on
    12026-03-01
    22026-03-01
    82026-03-08
    132026-03-15
    162026-03-22
    172026-03-22
  7. 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 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.

More practice sets

Check your level

The free SQL test takes about 10 minutes and tells you which lesson to start with.