Calculate Age from Birthdate
Calculate Age from Birthdate
Tags: Basics
Credit: CodingChallenge
Difficulty: Beginner
Type: Text
Category: Practice
Time Allowed: 5 s
Description:
Write a function that takes a birthdate as a string in the format "YYYY-MM-DD" and returns the age in years as an integer. This problem is designed to help you practice working with dates and calculating time differences
. The function should accept one parameter and return the age.
Constraints:
- The input will be a
string
representing a valid date in the format "YYYY-MM-DD". - The function should
return
aninteger
representing the age in years. - Use the
datetime
module.
Example:
- Input:
"1990-01-01"
- Output:
33
// (Assuming the current year is 2023)
Test Case | Input | Expected Output |
---|---|---|
1 | "1990-01-01" | 33 |
2 | "2000-06-15" | 23 |
3 | "1985-10-05" | 38 |
4 | "1970-12-31" | 52 |
Leave a Comment
Please login to leave a comment.