PHP implementation of converting date to age

不言
Release: 2023-04-02 16:12:02
Original
2194 people have browsed it

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;

    }
Copy after login
 $data["birthday"] = $this->howOld($birthday);
        var_dump($data["birthday"]);
Copy after login

 

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template