★ wanayoo — archive 1999 http://www.php.net/manual/function.checkdate.phpNouvelle recherche | Portail wanayoo

PHP Home Page

Manual Table of Contents
Up to Date/time
Quick Reference
Date/time
* checkdate
* date
* getdate
* gettimeofday
* gmdate
* gmmktime
* gmstrftime
* microtime
* mktime
* strftime
* time
Manual: checkdate
View the source code for this pageSearch the site



Previous page
 Date/time
date 
Next page


checkdate

checkdate -- Validate a date/time

Description

int checkdate(int month, int day, int year);

Returns true if the date given is valid; otherwise returns false. Checks the validity of the date formed by the arguments. A date is considered valid if:

  • year is between 0 and 32767 inclusive

  • month is between 1 and 12 inclusive

  • day is within the allowed number of days for the given month. Leap years are taken into consideration.


User Contributed Notes: checkdate


aulbach@unter.franken.de
27-Jan-1999 08:12
<B>Tip:</B>

mySQL for example, has very good date-routines. It eats nearly every kind of date correctly.
So if you use a DB, it is not so a bad idea to use the routines from it, cause the routines in the DB also can correct the year. This trick can ship you around problems with Y2K.

You can do for example:

$formdate="28.01.99"; # comes normally from your input form, her e.g. german date
# This lines splits it up: one or more digits, seperated by non-digits
$mydate=ereg("([[:digit:]]+)[^[:digit:]]([^[:digit:]])[^[:digit:]]([[:digit:]]{2,4})",$fromdate,$regs);
$newdate="$regs[3]-$regs[2]-$regs[1]"; # date is now "99-01-28"
$r=mysql("BLA_DB","SELECT UNIX_TIMESTAMP('$newdate') as d");
if ($d=mysql_result($r,0,"d")>0) {
     # Date is correct 
     echo Date("d.m.Y",$d); # will show now 28.01.1999
     # remark, that mySQL assumes, that years < 70 or so are in year 2000 and up
}



thovden@bigfoot.com
09-Dec-1999 06:00
aulbach@unter.franken.de 's tip on dates/mysql contains an error in the regexp: the correct line should read: $mydate=ereg("([[:digit:]]+)[^[:digit:]]([[:digit:]]+)[^[:digit:]]([[:digit:]]{2,4})",$fromdate,$regs);


ezra_freedman@yahoo.com
22-Dec-1999 12:46
things to look out for... Because checkdate accepts years between 0 and 32767 inclusive, you may want to include a cutoff year in your code when checking dates entered in a form by users. i.e. checkdate(1,1,199) returns true, as this is a valid date. Another consequence of the range of years accepted is that checkdate(1,1,"") will return true. If a user leaves a year form field blank, php will turn this into an int (0) and checkdate will look up the date in the year 0. Fortunately, PHP recognizes 0 as a leap year, so checkdate(2,29,"") returns true.


waller@edgeglobal.com
04-Jan-2000 04:54
something I found useful for varibalizing dates to to date checks\n if ($year."-".$month."-".$day <= date("Y-m-d")) { echo("date not acceptable"); $errorflag = "yes"; } where a form has three input text fields named accordingly.


andreaboscolo@supereva.it
15-Mar-2000 05:03
Andrea Boscolo Example: &lt;?php $val = checkdate($month, $day, $year); if ($val) { echo "the date are true"; } else { echo "the date are false"; } ?>


andreaboscolo@supereva.it
15-Mar-2000 05:04
Andrea Boscolo Example:
&lt;?php

$val = checkdate($month, $day, $year);

if ($val) {
	echo "the date are true";
	} else {
		echo "the date are false";
	}
?>



crazydude@mail.ru
06-May-2000 04:38
What is this: checkdate("01","01",";"); The above command returns true. I'm wrong?


 About Notes


Previous page
 Date/time
date 
Next page



Site Statistics


Who's responsible for this?
Top of this page

Site
Hosting:



Located in
United States
Elements of this website are subject to copyright.
Questions about installing or using PHP should be directed to one of the mailing lists.
Only questions about the website should be directed to webmaster@php.net.