finding number of days in certain month

function getDaysForMonth($month,$year=''){
	$febMonth=28;
	if(trim($year)!=''){
		$isLeap=intval((($year % 4) == 0) && ((($year % 100) != 0) || (($year %400) == 0)));
		if($isLeap==1)
			$febMonth=29;
	}

	if($month%2==1 || $month==8)
		$days=31;
	else if($month==2)
		$days=$febMonth;
	else
		$days=30;
}

This Post Has One Comment

  1. Hi Pasa,

    Nice to see your php blog and got chance to look at the first function.

    How do you handle leap year? Feb 29. There is no condition for it on your function.
    I believe, you’ll enhance your function.

    Thanks,
    Ram

Leave a Reply

Close Menu