note 41964 added to function.cal-days-in-month

From: Date: Tue, 27 Apr 2004 21:43:51 +0000
Subject: note 41964 added to function.cal-days-in-month
Groups: php.notes 
Request: Send a blank email to php-notes+get-68908@lists.php.net to get a copy of this message
How about this one: 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. ---- Manual Page -- http://www.php.net/manual/en/function.cal-days-in-month.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+41964 Delete -- http://master.php.net/manage/user-notes.php?action=delete+41964&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+41964&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#68908) next »