note 41964 deleted from function.cal-days-in-month by tularis

From: Date: Tue, 01 May 2007 14:48:18 +0000
Subject: note 41964 deleted from function.cal-days-in-month by tularis
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-126089@lists.php.net to get a copy of this message
Note Submitter: rshowalter at mtsinai dot on dot ca ---- How about this one: <?php function daysinmonth($month, $year) { $days=31; while(!checkdate($month, $days, $year)) $days--; return $days; } ?> Not exactly a one-line solution, but easy to follow, not limited to 1970-2038 (but don't use it after the year 32767) and uses a built-in function that's always available. Be sure that $month and $year are valid, or the loop will run forever. Possibly add: && $days>0 to the while condition. This would return 0 as your error code.

« previous php.notes (#126089) next »