← All Exercises
Python Datetime Arithmetic
intermediatepython
Background
Date arithmetic is essential for age calculation, scheduling, billing cycles, and time-based business logic.
Problem
Write a function that takes a birth date string and returns the age in years, accounting for whether the birthday has occurred this year.
Input
A birth date string in YYYY-MM-DD format.
Output
An integer representing the age in complete years.
Sample tests
Sample 1
Input: "2000-01-15" (on 2025-01-20)
Expected: 25
Your solution
Learning objective
Learn datetime parsing, date arithmetic, and birthday boundary handling.