Given current date and birth date, find the present age.
Input : Birth date = 07/09/1996 Present date = 07/12/2017 Output : Present Age = Years: 21 Months: 3 Days: 0 t Age = Years: 7 Months: 11 Days: 21
While calculating the difference in two dates we need to just keep track of two conditions that will do.
- If the current date is less than that of the birth date, then that month is not counted, and for subtracting dates we add number of month days to the current date so as to get the difference in the dates.
- If the current month is less than the birth month, then the current year is not taken into count as this year has not been completed and for getting the difference of months, we subtract by adding 12 to the current month.
- At the end we just need to subtract the days, months and years to get the difference after the two conditions are dealt with.
Below is the implementation of the above approach :
Present Age Years: 7 Months: 11 Days: 22
- Program to calculate the value of sin(x) and cos(x)
- Program to calculate value of nCr
- Python program to calculate age in year
- Program to calculate volume of Octahedron
- Program to Calculate the Perimeter of a Decagon
- Program to calculate Root Mean Square
- Program to calculate GST from original and net prices
- Program to calculate distance between two points
- Program to calculate Profit Or Loss
- Program to calculate area of Enneagon
- Program to calculate Area Of Octagon
- Program to calculate distance between two points in 3 D
- Program to calculate area of a Tetrahedron
- Program to calculate volume of Ellipsoid
- Program to calculate area and perimeter of Trapezium
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.
Improved By : vt_m