timgavin
timgavin

Reputation: 5166

Laravel: Comparing Dates

Is there a better way of comparing dates than this? Seems clunky...

if(Carbon::parse($member->cancel_at)->toDateString() == Carbon::today()->toDateString())
{
    // do stuff
}

Upvotes: 1

Views: 111

Answers (1)

Alexey Mezenin
Alexey Mezenin

Reputation: 163758

In your case you could try isToday() method:

$canceled = Carbon::parse($member->cancel_at);

if ($canceled->isToday()) {
    ....

You can make it shorter if you'll set cancel_at as instance of Carbon with $dates array. Then you'll be able to use just:

if ($member->cancel_at->isToday())

Upvotes: 2

Related Questions