我尝试在数据库和DateTime
的记录之间进行差异<?php
$link = mysqli_connect("localhost", "root", "", "abb");
$result = mysqli_query($link, "SELECT * FROM submission_abb");
$row=mysqli_fetch_array($result);
$submission = $row['submission'];
$selesai = new DateTime();
$hitung = $submission->diff($selesai);
$result = $hitung->format('Y-m-d');
if($hitung->d <=3){
echo $result . "Ontime";
}else{
echo $result . "Over time";
}
?>
答案 0 :(得分:0)
您的问题是您在字符串值上调用diff()
,因为$submission
包含一个字符串的日期值。您只能在diff()
对象上拨打DateTime()
。
<?php
$link = mysqli_connect("localhost", "root", "", "abb");
$result = mysqli_query($link, "SELECT * FROM submission_abb");
$row=mysqli_fetch_array($result);
$submission = new DateTime($row['submission']);
$selesai = new DateTime();
$hitung = $submission->diff($selesai);
$result = $hitung->format('Y-m-d');
if($hitung->d <=3){
echo $result . "Ontime";
}else{
echo $result . "Over time";
}
?>