follow this link i hope its helped
https://laracasts.com/discuss/channels/eloquent/how-to-compare-with-date-in-where
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I have a field, start_date and end_date, and also duration (int). if the duration is 1, that means the post would be active for 24 hours, and if the duration is 3; the post would be active for 3 days. Now, I want to compare the start date, and end date, if the duration equalTo 1 (Post is active for 24hours)-> send notification when start_date hours is equalTo 12 , Then update date field to null when property has expired, same process for the duration 3 (3 days), send notification every 24 hours and update start_date to Carbon::now, repeat process every 24 hours until end date is equal to 12 hours send notification, lastly, update datefield to null when property expires. Below is my code Basically am trying to send notification of boosted property every 24 hours depending on the duration of the boost. eg 1, 3, 7, 14 days respectively. Am using laravel schedule.
//THis is the step that would process the boost reminder
$boostPropertys = Property::where('property_boost_status', 1)
->where('property_boost_end_date', '>=', Carbon::now())
->get();
// dd($boostPropertys);
if ($boostPropertys){
foreach($boostPropertys as $boostProperty) {
//Get time from db and convert to carbon instance.
$startTime = (new Carbon)->parse($boostProperty->property_boost_start_date);
$endTime = (new Carbon)->parse($boostProperty->property_boost_end_date);
//Check if start date is equal to 24 hours with the current date. Note: My intention in the if statement is to retrieve every boost whose startTime == 1 day or 24 hours
if($startTime->addDays(1) == Carbon::now() and $endTime > Carbon::now()){
echo $boostProperty->id ."\n";
}
else{
echo "No start time is == to current Time";
}
}
}
else{
echo 'No Result for Boosted Property';
}
while testing this, I observed that Carbon::now() returns e.g 2019-04-24 16:24:00pm. My expectation in the above code is when startTime date: 2019-04-23 16:05:58 ->addDays(1) :
//So example
if ( $newStartDate eg.(2019-04-24 16:05:58) == Carbon::now() e.g(2019-04-24 16:24:00pm) ) {
//However Nothing happens, my guess is because of the seconds different
//I expected this to return true, so i can send notification and update startdate
}else {
return false;
}
Note: Am updating start_date to Carbon::now each time the system update start_date to carbon::now and send notification; so that i can fetch boosted properties first, before properties that are not boosted
$duration = // store the number of days. eg 1, 3, 7..
$start_date = // carbon::now()
$end_date = // future date eg 3 days time, 1 day time 7 days time etc
$boost_status = //1 means active boost // update to 0 when boost expires
//Code to Retrieve Property in view to display boostedProperties first, before properties that are not boosted,
//Please is this logic correct??
$myproperties = Property::where('properties.admin_status', 1)
->orderBy('property_boost_status', 'DESC')
->orderBy('property_boost_duration', 'DESC')
->orderBy('property_boost_start_date', 'DESC')
->orderBy('created_at', 'DESC')
->get();
@neeonline Pls, help me crosscheck this, my intention is that every 24 hours the system shud send a notification to the users based on their active boost. The duration of boost cud range from 1 day to 14 days. so now am checking the difference between currentTime to BoostStartDate if result == 24 hours. system shud update BoostStartDate to latest time. Intention: to make it easy to fetch active boostedProperty record first and to send Notification to the user of the remaining time. Please read my question and see if this implementation would provide a solution to it.
$boostStartDate = (new Carbon)->parse($boostProperty->property_boost_start_date);
$boostEndDate = (new Carbon)->parse($boostProperty->property_boost_end_date);
//Check Differences in Hours
$curentTime = Carbon::now();
$diffInStartDate = $curentTime->diffInHours($boostStartDate); //24 means 1 day to d future
$diffInEndDate = $boostEndDate->diffInHours($curentTime); //72
//echo $diffInStartDate . '..';
if($diffInStartDate == 24 && $diffInEndDate > 12) {
//Boost active for 24 hours; Update startDate to currentTime and sendNotification
}
if($diffInEndDate == 12) {
//if The difference is == 12 that means the boost is less than a day and it would expire in 12 hours
}
if($diffInEndDate <= 0) {
//That means the boost has expired.
}
Please or to participate in this conversation.