There are two ways to find out the number of days for a given month. The first is to use the date() function in conjunction with the mktime() function to create a date and format this value as the number of days in a given month.
$monthDays = date("t",mktime(0, 0, 0, 12, 1, 2008));
The second way is to use the function cal_days_in_month(). This function takes three parameters.
- Canelday: There are a number of different forms of calendar to chose from. The one most English speaking people are interested in is the CAL_GREGORIAN calendar. Take a look at a full list of calendar constants.
- Month: An integer representing the month (1 - 12).
- Year: An integer representing the year.
To find out the number of days in the month of December of 2008 you could use the following.
$monthDays = cal_days_in_month(CAL_GREGORIAN, 12, 2008);