Home > Article > Backend Development > PHP implementation of converting date to age
This article mainly introduces the implementation of converting PHP root date into age. It has a certain reference value. Now I share it with everyone. Friends in need can refer to it
/* * @param cheack age */ function howOld($birth) { $birthday = strtotime($birth);//int strtotime ( string $time [, int $now ] ) $year = date('Y', $birthday); if(($month = (date('m') - date('m', $birthday))) < 0){ $year++; }else if ($month == 0 && date('d') - date('d', $birthday) < 0){ $year++; } return date('Y') - $year; }
$data["birthday"] = $this->howOld($birthday); var_dump($data["birthday"]);
The above is the entire content of this article. I hope it will be helpful to everyone’s study. For more related content, please pay attention to the PHP Chinese website!
Related recommendations:
PHP
Implementation of using QQ mailbox to send emails
php package zip image download method
The above is the detailed content of PHP implementation of converting date to age. For more information, please follow other related articles on the PHP Chinese website!