How can I calculate the age of a person in year, month, days?

前端 未结 11 1259
谎友^
谎友^ 2020-11-27 05:52

I want to calculate the age of a person given the date of birth and the current date in years, months and days relative to the current date.

For example:

<         


        
11条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-11-27 06:32

    Since you are obviously using python: Create to datetime objects, one with "birthday" and one with "now", subtract them and read the age from the resulting timedelta object.

    Why bothering with things like leap years?

提交回复
热议问题