Would like to retrieve all days and date for a given month. Have this currently which shows all the days for the current month, but how do I parse in a specified month instead?<
I'm surprised nobody mentioned PHP's built-in, no extra extensions DateTime
class.
format('t');
print_r($daysInAugust2020);
You'll have to append some day to your YYYYMM
string, but it's not that hard: every month has a 1st. So you can always add 01
.
The trick here is the t
format, which just returns the number of days in the month the date is in. If you're trying to get this month's amount of days, it's even easier. Just running the date()
function creates a DateTime set to right now, so the above code becomes: