84. Age in Whole Years
MediumDates & Timestrftimewhole-year age
Computing age as (today - birthday) / 365.25 is fractional and error-prone. The clean integer trick is to compare the two dates formatted as '%Y%m%d': subtract the year, then subtract 1 more if the birthday's month-and-day hasn't been reached yet this year.
Use a fixed reference date of '2024-06-15' (not today) so results are stable.
Task: for each person return name, birthday, and age — their whole-year age as of '2024-06-15'. The result must be an integer. Order by name.
Output columns, in order: name, birthday, age.
Tables
Loading schema…
Expected outputrows must come back in this order
Computing expected output…
This is the result for the example data above. On Submit your query is graded against this example plus 4 hidden edge cases — 5test cases in all. A sloppy query that only fits the example won't pass.
SQL· SQLite · runs in your browser
⌘/Ctrl+↵ run · ⇧⌘/Ctrl+↵ submit
Run a query to see its output here.