note 63335 added to function.checkdate
| From: | moklet at osu1 dot php dot net | Date: | Mon, 20 Mar 2006 13:34:31 +0000 |
| Subject: | note 63335 added to function.checkdate | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-106102@lists.php.net to get a copy of this message | ||
ANd now it accepts date formats like yyyy/mm/dd as well
<?php
/**
* Checks for a valid date
*
* @param string Date in the format given by the format parameter.
* @param integer Disallow years more than $yearepsilon from now (in future as well as in past)
* @param string Formatting string. Has to be one of 'dmy', 'dym',
'mdy', 'myd', 'ydm' or 'ymd'. (Default is 'ymd'
for ISO 8601 compability)
* @return array [ year, month, day ]
* @since 1.0
*/
function datecheck($date, $yearepsilon=5000, $format='ymd') {
$date=str_replace("/", "-", $date);
$format = strtolower($format);
if (count($datebits=explode('-',$date))!=3) return false;
$year = intval($datebits[strpos($format, 'y')]);
$month = intval($datebits[strpos($format, 'm')]);
$day = intval($datebits[strpos($format, 'd')]);
if ((abs($year-date('Y'))>$yearepsilon) || // year outside given range
($month<1) || ($month>12) || ($day<1) ||
(($month==2) && ($day>28+(!($year%4))-(!($year%100))+(!($year%400)))) ||
($day>30+(($month>7)^($month&1)))) return false; // date out of range
return array(
'year' => $year,
'month' => $month,
'day' => $day
);
}
?>
----
Server IP: 66.163.161.117
Probable Submitter: 198.54.202.234 (proxied: 165.145.207.190, 196.25.253.14)
----
X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER
autolearn=no version=2.64
----
Manual Page -- http://www.php.net/manual/en/function.checkdate.php
Edit -- http://master.php.net/note/edit/63335
Del: integrated -- http://master.php.net/note/delete/63335/integrated
Del: useless -- http://master.php.net/note/delete/63335/useless
Del: bad code -- http://master.php.net/note/delete/63335/bad+code
Del: spam -- http://master.php.net/note/delete/63335/spam
Del: non-english -- http://master.php.net/note/delete/63335/non-english
Del: in docs -- http://master.php.net/note/delete/63335/in+docs
Del: other reasons-- http://master.php.net/note/delete/63335
Reject -- http://master.php.net/note/reject/63335
Search -- http://master.php.net/manage/user-notes.php