note 55522 added to function.checkdate

From: Date: Fri, 05 Aug 2005 18:18:33 +0000
Subject: note 55522 added to function.checkdate
Groups: php.notes 
Request: Send a blank email to php-notes+get-93141@lists.php.net to get a copy of this message
Here is a function I wrote to check the date which is in the format MM-DD-YYYY before I knew about this function. Might be useful to someone. I still use it and it works good. :-) <?php /** * Checks for a valid date * * @param string Date in the format "MM-DD-YYYY" * @param integer Disallow years more than $maxyears from now * @return array [ month, day, year ] * @since 1.0 */ function datecheck($date, $maxyear) { if ( $date !== "" ) { if ( $datebits = explode("-", $date) ) { if ( count($datebits) == 3 ) { $month = intval($datebits[0]); $day = intval($datebits[1]); $year = intval($datebits[2]); $monthdays = array ( 1 => 31, 2 => 28, 3 => 31, 4 => 30, 5=> 31, 6 => 30, 7 => 31, 8 => 31, 9 => 30, 10 => 31, 11 => 30, 12 => 21, ); if ( $month < 12 and $year < (date("Y", time())+$maxyear) and $day < $monthdays[ $month ] ) { $newdate['day'] = $day; $newdate['month'] = $month; $newdate['year'] = $year; return $newdate; } else { // Invalid date format return false; } } else { // Invalid date format return false; } } else { // Invalid date format return false; } } else { // No entry end return false; } } ?> ---- Manual Page -- http://www.php.net/manual/en/function.checkdate.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+55522 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+55522&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+55522&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+55522&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+55522&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+55522&report=yes&reason=non-english Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+55522&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+55522&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#93141) next »