note 69693 deleted from function.checkdate by bjori

From: Date: Wed, 11 Oct 2006 08:26:32 +0000
Subject: note 69693 deleted from function.checkdate by bjori
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-118396@lists.php.net to get a copy of this message
Note Submitter: aognio -NOSPAM- gmail.com ---- I wrote this function based on the ones showed above but adding extra flexibility so you can use YY-MM-DD. DD-MM-YY, YYYY-MM-DD, YYYY-DD-MM and all other combinations and also dots, slashes and commas as separators. function datetime_check_date_string($date_string) { $result = false; /* Checking for a match in the form MM-DD-YY(YY) or DD-MM-YY(YY) with alternative separators */ if (ereg('^([0-9]{1,2})[-,/.]([0-9]{1,2})[-,/.](([0-9]{2})|([0-9]{4}))$', $date_string)) { $date_array = split('[-,/.]', $date_string); /* Let's try MM-DD */ $m=$date_array[0]; $d=$date_array[1]; $y=$date_array[2]; $result = checkdate($m, $d, $y); /* MM-DD failed, let's try DD-MM */ if ($result===false) { $m=$date_array[1]; $d=$date_array[0]; $y=$date_array[2]; $result = checkdate($m, $d, $y); } /* Checking for a match in the form YY(YY)-MM-DD or YY(YY)-DD-MM with alternative separators */ } elseif (ereg('^(([0-9]{2})|([0-9]{4}))[-,/.]([0-9]{1,2})[-,/.]([0-9]{1,2})$', $date_string)) { $date_array = split('[-,/.]', $date_string); /* Let's try MM-DD */ $m=$date_array[1]; $d=$date_array[2]; $y=$date_array[0]; $result = checkdate($m, $d, $y); /* MM-DD failed, let's try DD-MM */ if ($result===false) { $m=$date_array[2]; $d=$date_array[1]; $y=$date_array[0]; $result = checkdate($m, $d, $y); } } return $result; }

« previous php.notes (#118396) next »