How to calculate days in a month using PHP

413

If you want to calculate number of days in specific month year then In php there is pre-define function called cal_days_in_month which return the number of days in a month for a given year and calendar.

Copy Paste below function in your PHP file and use it to calculate days in a month.

function getDays($month, $year) {
 $d=cal_days_in_month(CAL_GREGORIAN,$month,$year);
 return $d." Days";
}

This simple one line PHP function provides the number of days in a month, taking into account leap years as well.

See Live Demo.

DEMO