Search code examples
phplaraveldatephp-carbon

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

  • You can do so

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