Answers for "calculate age in php"

PHP
1

calculate person age by birthdate php

public function getAge($date)
    {
        
        $dob = new DateTime($date);
        
        $now = new DateTime();
         
        $difference = $now->diff($dob);
         
        $age = $difference->y;
         
        return  $age;
    }
Posted by: Guest on July-11-2020
0

get age in months php

$interval = date_diff(date_create(), date_create('2008-01-01 10:30:00'));
echo $interval->format("You are  %Y Year, %M Months, %d Days, %H Hours, %i Minutes, %s Seconds Old");
Posted by: Guest on April-29-2021

Browse Popular Code Answers by Language