如何将借款纳入我的计算罚款

时间:2017-08-27 12:01:37

标签: php

我想在代码中输入一个$borrowdate,因为我认为这就是为什么我的处罚会不断更新代码,即使它已经返回了。这是表格August 27日期是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'");

1 个答案:

答案 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'");