0

Hi everyone,
i need help here..

i want to calculate age of user.... but i am getting this error

****Catchable fatal error: Object of class DateInterval could not be converted to string in C:\xampp****

while($row=mysqli_fetch_assoc($data))
    {   
        $date=$row['Dateofbirth'];
    }

    $dob= new DateTIME($date);
    $interval=$dob->diff(new DateTIME);

Edited by phoenix254

2
Contributors
2
Replies
15
Views
2 Years
Discussion Span
Last Post by phoenix254
1

This works for me:

$dob= new DateTime($date);
$interval=$dob->diff(new DateTime);

echo $interval->format('%Y');

However, method chaining allows this:

$dob = new DateTime($date);
echo $dob->diff(new DateTime())->format('%Y');

Edited by diafol

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.