note 54989 added to function.checkdate

From: Date: Thu, 21 Jul 2005 17:58:39 +0000
Subject: note 54989 added to function.checkdate
Groups: php.notes 
Request: Send a blank email to php-notes+get-92261@lists.php.net to get a copy of this message
Here's a date validation snippet I wrote, since I wasn't able to find one that was flexible enough. It accepts dates in m-d-y format (2- or 4-digit year) and both dashes and slashes as separators. $strDate = $yourDate; $isValid = false; if (ereg('([0-9]{1,2})[-,/]([0-9]{1,2})[-,/](([0-9]{2})|([0-9]{4}))', $strDate)) { $dateArr = split('[-,/]', $param->value); $m=$dateArr[0]; $d=$dateArr[1]; $y=$dateArr[2]; $isValid = checkdate($m, $d, $y); } if (!$isValid) { // take appropriate action } // then, to obtain the timestamp $date = mktime(null,null,null,$m,$d,$y); ---- Manual Page -- http://www.php.net/manual/en/function.checkdate.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+54989 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+54989&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+54989&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+54989&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+54989&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+54989&report=yes&reason=non-english Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+54989&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+54989&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#92261) next »