I would like to calculate the difference between two php dates. But I get the following error:
Notice: Undefined variable: difference in C:\wamp\www\HR version 1.3\Applicant_Workdetails.php on line 68
I would also like to know if its best practice to calculate the difference this way.
if (isset($_GET['success']) && empty($_GET['sucess'])) {
    echo 'Submitted Successfully' . ' ';
    printf("%d years, %d months, %d days\n", $difference->y, $difference->m, $difference->d);  //This is line 68
} else {
    if (empty($_POST) === false && empty($errors) === true) {
        $startdate = $_POST['StartDate'];
        $enddate = $_POST['EndDate'];
        $datetime1 = new DateTime($startdate);
        $datetime2 = new DateTime($enddate);
        $difference = $datetime1->diff($datetime2);
        //Submit Workdetails to the database
        $personal_workdetails = array(
            'IndustryName' => $_POST['IndustryName'],
            'Occupation' => $_POST['Occupation'],
            'Position' => $_POST['Position'],
            'Job_description' => $_POST['Job_description'],
            'StartDate' => $startdate,
            'EndDate' => $enddate,
            'Personid' => $Personid,
            'Jobid' => $jobid);
        personal_workdetails($personal_workdetails);
        //redirect
        header('Location: Applicant_workdetails.php?success');
        exit();
    } else if (empty($errors) === false) {
        //output errors if the errors array is not empty
        echo output($errors);
    }
}
 
     
     
     
    