I want to calculate person's age in months plus days using date of birth (example: 1986-08-23).
For example:
0 months and 25 days old.
5 months and 20 days old.
150 months and 4 days old.
285 months and 30 days old.
Any Idea? Thanks.
Age Calculation in Months NOTE: We divide the days by 30.5 because months alternate with 30 and 31 days. Hence the age in months for the given date of birth is 415 Months 16 Days since the DOB 26-08-1980 as of 11-05-2015.
In MySQL, you can use the inbuilt TIMESTAMPDIFF() function to compute the difference between two dates and return a value either in days, months or years. See the basic syntax below. mysql> SELECT TIMESTAMPDIFF(MONTH, FIRST_DATE, SECOND_DATE);
Basic Excel formula for age in years This conventional age formula can also be used in Excel. The first part of the formula (TODAY()-B2) returns the difference between the current date and date of birth is days, and then you divide that number by 365 to get the numbers of years.
$date = new DateTime('1990-10-13');
$diff = $date->diff(new DateTime());
printf("%d months and %d days old", $diff->y*12 + $diff->m, $diff->d);
Note that DateTime::diff()
requires PHP 5.3.0 or higher.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With