我正在尝试执行计算,以使用日期格式正确的if语句检查日期是否在其他两个日期之间,但是我似乎仍然遇到时间戳错误。对于如何解决它的任何帮助将不胜感激。
$Query = mysqli_query($con, "SELECT * FROM tblrental WHERE `CARID` = '".$Car."'");
$row3 = mysqli_fetch_assoc($Query);
$ARTakeOut = $row3\['TakeOutDate'\];
$ARReturn = $row3\['ReturnDate'\];
$ARDaysRented = $row3\['DaysRented'\];
$ARDaysRented = (round($ARDaysRented/2));
$MidDate = date('Y-m-d', strtotime($ARTakeOut . ' + '.$ARDaysRented.' days'));
echo $MidDate; ?> <br> <?PHP
echo $ARTakeOut; ?> <br> <?PHP
echo $ARReturn; ?> <br> <?PHP
if (
$MidDate->getTimestamp() > $ARTakeOut->getTimestamp() &&
$MidDate->getTimestamp() < $ARReturn->getTimestamp()){
echo "is between";
}else{
echo "NO GO!";
}
答案 0 :(得分:4)
$MidDate
,$ARTakeOut
和$ARReturn
都是字符串($MidDate
是date
的输出,其他是从数据库中读取的),而不是{ {1}}个对象。如果要使用DateTime
,则需要将它们变成DateTime
对象:
getTimeStamp
请注意,在您的$ARTakeOut = new DateTime($row3['TakeOutDate']);
$ARReturn = new DateTime($row3['ReturnDate']);
$ARDaysRented = $row3['DaysRented'];
$ARDaysRented = (round($ARDaysRented/2));
$MidDate = clone $ARTakeOut;
$MidDate->modify("+ $ARDaysRented days");
echo $MidDate->format('Y-m-d'); ?> <br> <?PHP
echo $ARTakeOut->format('Y-m-d'); ?> <br> <?PHP
echo $ARReturn->format('Y-m-d'); ?> <br> <?PHP
和\
之前,我已经删除了多余的[