我有数据库date1会来,那date1我已经添加了3个月,那是date2我写了if条件但不起作用的代码
我已经在工作并且编写了一些代码,但是没有工作
$createDate = new DateTime($ac_join);
$strip = $createDate->format('d-m-Y');
$effectiveDate = date('d-m-Y', strtotime("+3 months", strtotime($last)));
输出会像这样
$最后值:25-04-2019
添加3个月后:27-07-2019
if($effectiveDate > $last )
{
// last value to 3 months content not display
}
我预计结果是如果条件仅在显示内容后满足3个月,否则将保留值显示
这是代码
<?php $sql ="SELECT * from `donor_register` ORDER BY `dnr_blood_donate` LIMIT 4 ";
$result = $conn->query($sql);
$dnrcount = $result->num_rows;
while($row = $result->fetch_assoc()){
$last = $row['dnr_blood_donate'];
$createDate = new DateTime($ac_join);
$strip = $createDate->format('d-m-Y');
$effectiveDate = date('d-m-Y', strtotime("+3 months", strtotime($last)));
if($effectiveDate > $last )
{ ?>
<div class="col-xl-3 col-lg-3 col-md-6">
<div class="single-member">
<a href="donor-profile.php?did=<?=$did;?>">
<div class="part-img">
<img src="assets/image/donor/<?=$image;?>" alt="Donor image" style="height: 250px; width: 250px;"/>
</div>
</a>
<div class="part-text">
<a href="donor-profile.php?did=<?=$did;?>">
<h3><?=$fullname;?></h3>
</a>
<h4>Blood group : (<?=$bgroup;?>)</h4>
</div>
<div class="part-social">
Last Blood Donation : <?=$last;?>
</div>
</div>
</div>
<?php $i++; } ?>
最佳答案
我认为您要计算两个日期之间的偏差,如果偏差大于3个月,请采取措施。在我的示例中,date_1
等于25-04-2019
,而date_2
等于now
。我想知道从date_1
到now
是否经过了3个月。
这是您的代码:
$date1 = new DateTime("25-04-2019"); //****** This is date_1 and in your code, you get this date from the database.
$date2 = new DateTime(); //****** This is date_2, I assume it is now.
$periodOfTime = 90; //****** 3 months
if ($date1->diff($date2)->days > $periodOfTime) {
echo "Three months passed from the date_1";
}
else {
echo "Less than three months passed from the date_1";
}