'Laravel Get Days In Month From Month Number?

In Laravel Application I have month number like 01, 02, 03 upto 12. I want to get all days in this month. I cannot use daysInMonth() as I do not have a date all I have is month number.

Carbon::now()->daysInMonth();

how can I make this?



Solution 1:[1]

You can do so

Carbon::now()->month($month_number)->daysInMonth;

// ...

Carbon::now()->month(02)->daysInMonth; // 28

Solution 2:[2]

You can also do this

Carbon::createFromDate(null, $number_of_month, 1)->daysInMonth;

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 mmabdelgawad
Solution 2 Sergio Fonseca