I have searched for this but did not find a perfect function in php. I want to get a php function that calculate person age only in months.
For example:
less then one month old.
5 months old.
340 months old.
Thanks
Using PHP's DateInterval
(available from 5.3.0), that's pretty easy:
$birthday = new DateTime('1990-10-13');
$diff = $birthday->diff(new DateTime());
$months = $diff->format('%m') + 12 * $diff->format('%y');
Now $months
will contain the number of months I've lived.
$birthday = new DateTime("June 21st 1986");
$diff = $birthday->diff(new DateTime());
$months = ($diff->y * 12) + $diff->m;
var_dump($months);
Something along these lines?
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