Search code examples
phpdatephp-carbon

Carbon::now() - only month


I couldn't find anywhere in documentation how to show current year or month with Carbon?

when i write this:

Carbon\Carbon::now('m');

it gives me the whole time stamp, but I just need the month

like

date('m');

but it must be Carbon!

How can I achieve this?


Solution

  • $now = Carbon::now();
    echo $now->year;
    echo $now->month;
    echo $now->weekOfYear;
    

    Update:

    even this works since Laravel 5.5^

    echo now()->month