Reputation: 188
I have database to date1 will came and that date1 i have added 3 months then that was date2 i wrote the code for if condition but not working
i have already working and write some of the code but not working
$createDate = new DateTime($ac_join);
$strip = $createDate->format('d-m-Y');
$effectiveDate = date('d-m-Y', strtotime("+3 months", strtotime($last)));
the Output Will came like this
$last Value : 25-04-2019
after added 3 months : 27-07-2019
if($effectiveDate > $last )
{
// last value to 3 months content not display
}
I expected out put is if condition will satisfy 3 months after only diplay the content other wise remain values display
Here is the Code
<?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++; } ?>
Upvotes: 0
Views: 69
Reputation: 201
I think you want to calculate the deference between two dates and if the deference is grater than 3 months, do an action. In my example, date_1
is equal to 25-04-2019
and date_2
is equal to now
. I want to know whether from date_1
to now
passed 3 months or not.
Here your code:
$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";
}
Upvotes: 4