我想计算两个 php 日期之间的差异。但我收到以下错误:
注意:未定义变量:第 68 行 C:\wamp\www\HR 版本 1.3\Applicant_Workdetails.php 中的差异
我还想知道以这种方式计算差异的最佳实践。
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);
}
}