Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

theUnforgiven's avatar

Now i need to try and get it to send an email 1 hour before by doing a command this should be fun!

mehany's avatar

you will probably like this way too

   // fires every time the date field is called from DB, where NameOfField is the name of the date column in the DB
        public function getNameOfFieldAttribute($date)
    {
    return Carbon\Carbon::parse($date)->format('m/d/Y h:i:s A') ->subHour();
    }
1 like
mstnorris's avatar

@em57 you shouldn't need that. Once you've added the $dates property they will be treated as Carbon instances.

theUnforgiven's avatar

Just can't get it to send 1 hour before now, brain freeze...

bashy's avatar

You doing a check every minute or so?

You will want to check if the time now is less than or equal to the action date AND action date is greater or equal to the time now -1hour

I can't even work it out right now, it's something like that, greater/less than :P

1 like
mehany's avatar
mehany
Best Answer
Level 13

edited... I tried something like this

$date = '16:30:00';

$timeToCompare = Carbon\Carbon::createFromFormat('H:i:s', $date)->format('H:i:s');
$timeNow = Carbon\Carbon::now()->format('H:i:s');

if($timeToCompare <= $timeNow ){

$diff = $timeToCompare - $timeNow;

echo $timeNow;
echo $timeToCompare;
echo $diff;

//returns an even number

}

So you probably try converting to a unix timestamp

1 like
Previous

Please or to participate in this conversation.