Carbon::now() - only month

lewis4u picture lewis4u · Nov 17, 2016 · Viewed 67.2k times · Source

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?

Answer

user2693928 picture user2693928 · Nov 17, 2016
$now = Carbon::now();
echo $now->year;
echo $now->month;
echo $now->weekOfYear;

Update:

even this works since Laravel 5.5^

echo now()->month