checking the date with php
bits of the code here are taken from php.net
to check the date in php you can use a function called checkdate() but to get it working in a clever way with a form use the function below
< ?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=200, $format='dmy') {
$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 rangereturn checkdate($month,$day,$year );
}?>
this will check the variable $date.
First of all it replaces any ‘/’ symbols with ‘-’.
Using the specified format ($format) it checks to see you have 3 bits (day ,month, year).
Using the range of dates ($yearepsilon) it checks that the date is in range.
Then php’s checkdate function is used - this checks to see whether that date actuall did, or could exist.Only if everything matches will the function return true - otherwise it will return false
The checkdate function is pretty smart - it knows every day of every year between 1 and 32767 inclusive. For instance if 29/2/2000 were entered (using the day, month, year format) checkdate would return true as 2000 was a leapyear.
Using the function:
If you had a field with the name ‘date’ in your form you could set an error variable if the date was invalid, then use that error variable tell the user they’d made a mistake.
< ?php
if (datecheck($_POST['date']) == false){
$error = 1;
}
else { echo "the date is fine";}?>


February 11th, 2007 at 12:17 am
Hello, my name is Alex, i’m a newbie here. I really do like your resource and really interested in things you discuss here, also would like to enter your community, hope it is possible:-) Cya around, best regards, Alex!
April 6th, 2007 at 7:25 am
[url=][/url]
May 9th, 2007 at 1:03 am
carnauba car wax…
ha-rd-po-rn-fu-ck 1718957 Master information for carnauba car wax….
May 30th, 2007 at 9:07 am
logo promotional item…
Reviews of logo promotional item….
May 31st, 2007 at 8:56 pm
florida income tax form…
Very actual information about florida income tax form….
June 1st, 2007 at 3:22 am
ross ohlendorf…
The best of ross ohlendorf….
June 7th, 2007 at 6:27 pm
mature twat…
ka-ka-sh-ka 1718957 Features of mature twat….
June 9th, 2007 at 12:48 pm
sierra ebony sex…
Books about sierra ebony sex….
June 9th, 2007 at 4:55 pm
gay naked chat…
Relevant gay naked chat…
June 9th, 2007 at 9:34 pm
vagina hairy…
This site contains relevant information about vagina hairy….
August 25th, 2007 at 6:28 am