×

sql · level 2 · unit 7 · lesson 3

  1. meet it
  2. guess first
  3. your turn
  4. fix it
  5. nailed it

Tap a green word if you get lost.

meet it

moves a date, and counts the days between.

date('2026-04-01', '+14 days') gives '2026-04-15'. The second part is a : it moves the date, and it knows how long each month is. '-7 days' and '+1 month' work too.

To count the days between two dates, turn each into a day number with julianday, then subtract. julianday('2026-05-01') - julianday('2026-04-15') is 16.

SQLite can read the real date, but then answers change every day. Reports here use a fixed today, '2026-05-01', so they give the same answer every run.

SELECT l.id, l.due,
  julianday('2026-05-01') - julianday(l.due) AS days_late
FROM loans l
WHERE l.returned IS NULL AND l.due < '2026-05-01'
ORDER BY days_late DESC;

julianday gives decimals when a time of day is included. Plain dates always give whole days.