Python Forum
Simple calculation using datetime
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Simple calculation using datetime
#1
Hi, How can i calculate age using date time without hardcoding current year? The way I want to solve and validate is as follows:
from datetime import date

def get_age(birth_year):
    """
    returns the age based on current year
    """
    current_year = date.today().year
    
    return 
validate age:


assertion('12a', get_age(1950), 71)
assertion('12b', get_age(1990), 31)
assertion('12c', get_age(2020), 1)
Reply


Messages In This Thread
Simple calculation using datetime - by mapypy - Feb-06-2021, 09:13 AM
RE: Simple calculation using datetime - by Serafim - Feb-06-2021, 11:01 AM
RE: Simple calculation using datetime - by Jeff900 - Feb-06-2021, 07:34 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020