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

ManoMahe's avatar

Can't able to use Carbon's yesterday() function like today() function stand alone

Hi there! Actually I'm a new being for Laravel, In my Laravel 9 project straight away I can able to use carbon date function of "today()" rather I don't get why I couldn't use "yesterday()"

What I have checked with as follows,

dd(today()); // showing today's date 
dd(yesterday()); // throws error

If I used like the following code return with yesterday date,

dd(Carbon::today()); // showing today's date 
dd(Carbon::yesterday()); // working fine

For learning, I'm in need of know why I can't able to use yesterday() method

0 likes
4 replies
Snapey's avatar

because the framework authors didn't think it was useful enough to justify creating a helper.

today() is a convenience helper.

You could create a pull request to suggest adding it, or you could use today()->subDay()

here is the today() function in its entirety

if (! function_exists('today')) {
    /**
     * Create a new Carbon instance for the current date.
     *
     * @param  \DateTimeZone|string|null  $tz
     * @return \Illuminate\Support\Carbon
     */
    function today($tz = null)
    {
        return Date::today($tz);
    }
}
2 likes
Snapey's avatar

You can also use Date::yesterday(); since Date facade returns an instance of Carbon.

ManoMahe's avatar

@Snapey Yeah, thanks. I already seen that and used with the help of Laravel doc.

Please or to participate in this conversation.