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);

Recommended Answers

All 2 Replies

Member Avatar for diafol

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');
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.