note 87250 added to function.checkdate

From: Date: Wed, 26 Nov 2008 16:47:01 +0000
Subject: note 87250 added to function.checkdate
Groups: php.notes 
Request: Send a blank email to php-notes+get-146992@lists.php.net to get a copy of this message
<?php /* ** check a date ** dd.mm.yyyy || mm/dd/yyyy || dd-mm-yyyy || yyyy-mm-dd */ function check_date($date) { if(strlen($date) == 10) { $pattern = '/\.|\/|-/i'; // . or / or - preg_match($pattern, $date, $char); $array = preg_split($pattern, $date, -1, PREG_SPLIT_NO_EMPTY); if(strlen($array[2]) == 4) { // dd.mm.yyyy || dd-mm-yyyy if($char[0] == "."|| $char[0] == "-") { $month = $array[1]; $day = $array[0]; $year = $array[2]; } // mm/dd/yyyy # Common U.S. writing if($char[0] == "/") { $month = $array[0]; $day = $array[1]; $year = $array[2]; } } // yyyy-mm-dd # iso 8601 if(strlen($array[0]) == 4 && $char[0] == "-") { $month = $array[1]; $day = $array[2]; $year = $array[0]; } if(checkdate($month, $day, $year)) { //Validate Gregorian date return TRUE; } else { return FALSE; } }else { return FALSE; // more or less 10 chars } } check_date('21.02.1983'); check_date('21-02-1983'); check_date('02/21/1983'); // Common U.S. writing check_date('1983-02-21'); // iso 8601 ?> ---- Server IP: 212.124.37.9 Probable Submitter: 217.225.16.120 ---- Manual Page -- http://www.php.net/manual/en/function.checkdate.php Edit -- https://master.php.net/note/edit/87250 Del: integrated -- https://master.php.net/note/delete/87250/integrated Del: useless -- https://master.php.net/note/delete/87250/useless Del: bad code -- https://master.php.net/note/delete/87250/bad+code Del: spam -- https://master.php.net/note/delete/87250/spam Del: non-english -- https://master.php.net/note/delete/87250/non-english Del: in docs -- https://master.php.net/note/delete/87250/in+docs Del: other reasons-- https://master.php.net/note/delete/87250 Reject -- https://master.php.net/note/reject/87250 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#146992) next »