Home  >  Article  >  Backend Development  >  PHP implementation of converting date to age

PHP implementation of converting date to age

不言
不言Original
2018-07-06 09:52:392195browse

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(&#39;m&#39;) - date(&#39;m&#39;, $birthday))) < 0){
            $year++;
        }else if ($month == 0 && date(&#39;d&#39;) - date(&#39;d&#39;, $birthday) < 0){
            $year++;
        }
        return date(&#39;Y&#39;) - $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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn