A date object understands leap years and month boundaries. date.fromisoformat converts a YYYY-MM-DD string, and subtracting two dates produces an interval with a days attribute.
A booking can cross a month boundary. Dates and timedeltas support calendar arithmetic.
from datetime import date, timedelta
departure = date.fromisoformat("2025-01-30")
arrival = departure + timedelta(days=3)
print(arrival.isoformat()) # 2025-02-02Adding an interval gives another date. Subtracting two dates instead gives a timedelta, whose days attribute counts whole days.
Return the number of days from checkout to return. Inputs are valid ISO dates and return is on or after checkout. Same-day returns take zero days.
loan_days("2024-02-28", "2024-03-01") # 2