How to easily compare dates with Carbon in Laravel

Categorized as Laravel Tagged

Hello, friends. Did you know that you don’t have to compare dates yourself to check if it’s in the past or in the future. Use Carbon library methods isFuture and isPast for that:

if($promo->activeUntil->isFuture()) {
    // do some promo code
}

if($account->activeUntil->isPast()) {
    // do some account renewal code
}

Leave a reply

Your email address will not be published.