PHP calculates age (one year old) based on birthday
<?php/** * 根据时间戳计算年龄 * @param $birth * @return mixed */functionhowOld($birth) {list($birthYear, $birthMonth, $birthDay) = explode('-', date('Y-m-d', $birth)); list($currentYear, $currentMonth, $currentDay) = explode('-', date('Y-m-d')); $age = $currentYear - $birthYear - 1; if($currentMonth > $birthMonth || $currentMonth == $birthMonth && $currentDay >= $birthDay) $age++; return$age; } ?>
The above introduces PHP to calculate age (one year old) based on birthday, including the content. For more related content, please pay attention to the PHP Chinese website (m.sbmmt.com) !
Related articles:
How to calculate age based on birthday in php
Example of how to calculate age/zodiac sign/constellation in php based on birthday