I am trying to count how many weekends (Saturday and Sunday) that falls in a given month. This will allow me to subtract these weekends to get number of actual weekdays required in my application.
What I am doing now is, firstly I created Carbon object like this:
$thisDate = Carbon::createFromDate(2014, 12, 2);
And then, I calculated the number of days in a month that falls in above date with the help of Carbon object like this
$daysInMonth = $thisDate->daysInMonth;
Now, I have got the number of days in a month. It is possible to find the number of weekends by looping each day of that month and checking whether it is weekend or not (something like CarbonObject->isWeekday) and increasing the counter but it seems quite messy.
Is there more elegant way to do this? I mean is there something better in CarbonObject that I am missing, which could give the result in much easier way?
Note: I am creating my application with the help of Laravel4.2
I have also read this: (But was wondering if there is Carbon-way solution) Get number of weekdays in a given month