How to get the age of a person from his date of birth | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

How to get the age of a person from his date of birth

I working in a project that requires me to generate the age of person (in years months and days)

14th Dec 2018, 1:14 PM
Abdala Osama Gaming
Abdala Osama Gaming - avatar
17 Answers
+ 1
The module is clever, its been written to have complete knowledge of leap years etc. You need to use the python documentation, find the module in it, and it explains the functions in the module, what they do and how they work. If your code works though, great. But I cant tell from the example if its aware of the varying days per month etc.
15th Dec 2018, 1:44 AM
Genghis
Genghis - avatar
+ 8
... and what programming language is it about?
14th Dec 2018, 1:26 PM
Tashi N
Tashi N - avatar
14th Dec 2018, 4:16 PM
Maninder $ingh
Maninder $ingh - avatar
+ 2
What have you done so far?
14th Dec 2018, 1:18 PM
Diego
Diego - avatar
+ 1
Sorry i forgot to mention that
14th Dec 2018, 1:28 PM
Abdala Osama Gaming
Abdala Osama Gaming - avatar
+ 1
I asked my math teacher and we both worked( like 5 minutes ) to find the answer and we found a good way
14th Dec 2018, 11:37 PM
Abdala Osama Gaming
Abdala Osama Gaming - avatar
+ 1
Now day = number of day we are in Days = the number of day in date of birth Age days = the number of day the human lived ------------------------------------ If days <now day : Age days = (Days + number of days in that month ) - now days Months - 1 Else Age days = now day - days ---------------------------------------------- And the samething in months and years
14th Dec 2018, 11:55 PM
Abdala Osama Gaming
Abdala Osama Gaming - avatar
+ 1
https://docs.python.org/3.6/tutorial/ Heres a link to the documentation generally, started with the tutorial so you know it exists. Just use the search bar at the top of the page to find the datetime module. Bookmark this site its the official manual. Use it often.
15th Dec 2018, 8:36 AM
Genghis
Genghis - avatar
+ 1
A good trick I use is finding the difference between millis between B day and today and convert it to any date format. This way is more accurate and very easy
15th Dec 2018, 1:23 PM
Seniru
Seniru - avatar
+ 1
Seniru Pasan That is an interesting idea. Do you have an example of that? I looked through your list of codes and didn't spot one.
15th Dec 2018, 6:10 PM
Decimis † 𝕯𝖊𝖈𝖎𝖒𝖎𝖘
Decimis † 𝕯𝖊𝖈𝖎𝖒𝖎𝖘 - avatar
0
It is python
14th Dec 2018, 1:28 PM
Abdala Osama Gaming
Abdala Osama Gaming - avatar
0
And I wanted to create a program that calculates the age of person in years,months and day . i have created the gui using tkinter already but the problem was how to convert that dob (date of birth) in three varibles (years , months , days) and thanks for responding
14th Dec 2018, 1:33 PM
Abdala Osama Gaming
Abdala Osama Gaming - avatar
0
Dont try and do it all by yourself, use the datetime module and save yourself a headache
14th Dec 2018, 10:31 PM
Genghis
Genghis - avatar
0
I still a beginner i started learning python a week ago , so i couldn't know what func to use from the datetime library there seems to be a lot of ways to do this but want a mathematical way , cause the leap years will confuse the module as bad as the difference in number of days in a month will do
14th Dec 2018, 11:34 PM
Abdala Osama Gaming
Abdala Osama Gaming - avatar
0
Thanks for answer , I haven't tested my code yet. But it look like using the module is easier , thank you I didn't know about the documentation on the web . can you please give a link to that documentation . and thank you for your support
15th Dec 2018, 1:55 AM
Abdala Osama Gaming
Abdala Osama Gaming - avatar
0
Thank you for that , see you on another question
15th Dec 2018, 10:46 AM
Abdala Osama Gaming
Abdala Osama Gaming - avatar
0
Thank you for that , see you on another question
15th Dec 2018, 10:46 AM
Abdala Osama Gaming
Abdala Osama Gaming - avatar