Object of class DateInterval could not be converted to int

Viewed 11

Write a program that will input your name and birthday and will display the Date and time of your input and display also your Age. Also the system will greet you Good Morning / Afternoon/Evening. The system will also inform you that you are young, very young, old, or very old condition: if age < 15 very young age > 15 and < 20 young age >= 20 and < 50 old age >= 50 very old

im stuck on the condition of the machine determining whether i'm very young, young and old if i run this code i always get the error of DateInterval could not be converted to int i'm at a loss of what to do

 if (isset($_GET['submit'])) {
        $result1= $_GET['Name'];
        $result2= $_GET['Bday'];
        $birthDate = $result2;
        $currentDate = date("d-m-Y");
        $age = date_diff(date_create($birthDate), date_create($currentDate));
        date_default_timezone_set("Asia/Kolkata");  
    $h = date('G');
    if($h>=5 && $h<=11)
    {
        echo "Good Morning $result1 ... <br>You are ".$age->format("%y years old, %m months and");
    }
    else if($h>=12 && $h<=15)
    {
        echo "Good Afternoon $result1 ... <br>You are ".$age->format("%y years old, %m months");
    }
    else 
    {
        echo "Good Evening $result1... <br>You are ".$age->format("%y years old, %m months and");
    }

if ($age < 15 ) 
{
    echo "you are very young";
}
else if($age < 50) 
{
    echo "you are young";
}   
else if($age < 51 ) 
{
    echo "you are old";
}
else if ($age >= 50 ) 
{
    echo "you are very old";
}
0 Answers
Related