我想在代码中输入一个$borrowdate
,因为我认为这就是为什么我的处罚会不断更新代码,即使它已经返回了。这是表格日期是8月27日,罚款不断进行。
$borrowdate = new Datetime($row['date_return']); // This code
$returndate = new Datetime($row['due_date']);
$currentdate = new Datetime();
$returndate->setTime(0,0);
$currentdate->setTime(0,0);
$interval = DateInterval::createFromDateString('1 day');
$period = new DatePeriod($returndate, $interval, $currentdate);
$weekendDays = 0;
$totalDays = 0;
foreach ( $period as $p ) {
$totalDays++;
if($p->format( "w" )==0) $weekendDays++;
}
echo "<p>Total days: $totalDays</p><p>Weekend days: $weekendDays </p>";
$fines = ($totalDays - $weekendDays) * 15;
echo "₱ ". $fines;
$fi = $row['borrow_details_id'];
mysqli_query($dbcon,"update borrowdetails set fines='$fines' where borrow_details_id = '$fi'");
答案 0 :(得分:0)
我刚刚为Borrowdate创建了一个setTime,我替换了$currentdate
在
$period = new DatePeriod($returndate, $interval, $currentdate);
<强> INTO 强>
$period = new DatePeriod($returndate, $interval, $borrowdate);
$borrowdate = new Datetime($row['date_return']);
$returndate = new Datetime($row['due_date']);
$currentdate = new Datetime();
$returndate->setTime(0,0);
$currentdate->setTime(0,0);
$borrowdate->setTime(0,0);
$interval = DateInterval::createFromDateString('1 day');
$period = new DatePeriod($returndate, $interval, $borrowdate);
$weekendDays = 0;
$totalDays = 0;
foreach ( $period as $p ) {
$totalDays++;
if($p->format( "w" )==0) $weekendDays++;
}
echo "<p>Total days: $totalDays</p><p>Weekend days: $weekendDays </p>";
$fines = ($totalDays - $weekendDays) * 15;
echo "₱ ". $fines;
$fi = $row['borrow_details_id'];
mysqli_query($dbcon,"update borrowdetails set fines='$fines' where borrow_details_id = '$fi'");