javascript - 如何从数据库中显示 3 个月内的 div 内容
问题描述
我有到 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)));
输出将是这样的
$last Value : 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";
}
推荐阅读
- excel - 尝试使用 VBA 索引匹配匹配并失败
- flutter - 如何使用 SingleChildScrollView 避免溢出
- linux - 如何在 linux 中使用 xmlstarlet 从 xml 中获取值
- java - 如何从两个表中检索数据
- java - 带有 JSON 的 Kafka 消费者?
- c++ - Why can't I access the object I created on the heap?
- android - Android UberEats like 搜索功能 UI
- r - R将当前行条目与下一行条目(在同一列上)进行比较
- functional-programming - 如何用任意类型的备忘录编写reduce函数
- javascript - 为什么 try/catch 块中的已定义变量在同一函数范围内显示未定义?