deroccha
deroccha

Reputation: 1183

carbon return number of days for a given year

Can Carbon return number of days for a given year?

    $dt = Carbon::parse($year . '-'. 1 .'-' . $from);

    var_dump($dt->format('z') + 1 );

this does not seems to work

Upvotes: 6

Views: 5151

Answers (3)

Andriy Orehov
Andriy Orehov

Reputation: 61

You can do this by using a comparison

echo 'Days in the year: ', ($dt->isLeapYear() ? 366 : 365);

Upvotes: 2

Jignesh Joisar
Jignesh Joisar

Reputation: 15115

You can get by using carbon property

Carbon::parse('2020-01')->daysInYear //for year

Carbon::parse('2020-01')->daysInMonth //for month

Upvotes: 5

deceze
deceze

Reputation: 522024

echo 'Days in the year: ', 365 + $dt->format('L');

L: Whether it's a leap year; 1 if it is a leap year, 0 otherwise

Upvotes: 6

Related Questions