note 37783 deleted from function.getdate by didou

From: Date: Thu, 22 Jan 2004 13:03:27 +0000
Subject: note 37783 deleted from function.getdate by didou
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-64017@lists.php.net to get a copy of this message
Note Submitter: ---- Here's how to figure the number of days in a month, leap years included. There's probably a better way to do this, but... function daysInMonth($month, $year) { $firstDay = mktime(0, 0, 0, $month, 1, $year); $dateData = getdate($firstDay); if ($month == 12) $daysInMonth = 31; else { $dayOfYearFirstOfThisMonth = $dateData['yday']; $firstOfNextMonth = mktime(0, 0, 0, $month + 1, 1, $year); $dateData = getdate($firstOfNextMonth); $dayOfYearFirstOfNextMonth = $dateData['yday']; $daysInMonth = $dayOfYearFirstOfNextMonth - $dayOfYearFirstOfThisMonth; } return $daysInMonth; }

« previous php.notes (#64017) next »