note 55522 deleted from function.checkdate by cece

From: Date: Tue, 15 Nov 2005 14:39:02 +0000
Subject: note 55522 deleted from function.checkdate by cece
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-98596@lists.php.net to get a copy of this message
Note Submitter: phil@philmo ---- 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; } } ?>

« previous php.notes (#98596) next »