当达到到期日时,而不是将罚款显示为25,它将显示0.当我在截止日期之后移动日期时,它将显示25。
这是我的代码。
$Borrow_Query = mysql_query("SELECT a.*, b.*, c.*, d.*, e.* FROM tblUser a, tblBorrowed b, tblResources c, tblCategory d, tblResourcesType e WHERE a.User_ID = '".$_GET['User_ID']."' AND b.User_ID = a.User_ID AND b.Accession_No = c.Accession_No AND c.Category_ID = d.Category_ID AND c.Type_ID = e.Type_ID ");
while ($Show = mysql_fetch_array($Borrow_Query)){
$DueDate = $Show['Due_Date'];
$timezone = "Asia/Manila";
if(function_exists('date_default_timezone_set')){
date_default_timezone_set($timezone);
$CURTIME2 = date('h:i a');
$CURDATE2 = date('F d,Y');
}
$AllowedTime_Query = mysql_query("SELECT * FROM tblAllowed_Days");
$AllowedTime_Row = mysql_fetch_array($AllowedTime_Query);
$Time = $AllowedTime_Row['Time'];
$Penalty_Query = mysql_query("SELECT * FROM tblPenalty");
$Penalty_Row = mysql_fetch_array($Penalty_Query);
$Fine = $Penalty_Row['Penalty'];
$Date_Time = $CURDATE2.' '.$Time;
if($Date_Time >= $DueDate){
$Fines = round((float)(strtotime($Date_Time) - strtotime($DueDate)) / (60 * 60 * 24) * ($Fine));
}else{
$Fines = 'No Penalty';
}
?>
答案 0 :(得分:0)
使用strtotime
功能在PHP中进行日期比较。
ex,if(strtotime($Date_Time) > strtotime($DueDate)){ ...
答案 1 :(得分:0)
好的,所以这个有效,但我不确定你试图从$Fines
获得什么,因为你把时间差乘以我认为的int然后四舍五入呢?
无论如何,你去,玩的东西。
<?php
$CURDATE2 = '2016-10-10';
$Time = '12:12:12';
$DueDate = '2016-09-09 12:12:12';
$Date_Time = $CURDATE2.' '.$Time;
$Fine = 20;
if( strtotime( $Date_Time ) > strtotime( $DueDate ) )
{
$Fines = round( (float) (strtotime( $Date_Time ) - ( strtotime( $DueDate ) ) / ( 60 * 60 * 24 ) * ( $Fine ) ), 2 );
}
else
{
$Fines = 'No Penalty';
}
echo $Fines;