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

PHP Home Page

Manual Table of Contents
Up to 日付/時刻
Quick Reference
English version of this pageGerman version of this pageItalian version of this pageFrench version of this pageHungarian version of this page
日付/時刻
* checkdate
* date
* getdate
* gettimeofday
* gmdate
* gmmktime
* gmstrftime
* localtime
* microtime
* mktime
* strftime
* time
* strtotime
Manual: checkdate
View the source code for this pageSearch the site



Previous page
 日付/時刻
 Updated
Sat, 12 Aug 2000
date 
Next page


checkdate

(PHP3 , PHP4 )

checkdate -- 日付の妥当性を確認します

説明

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

指定された日付が有効であればtrueを返し、そうでなければfalse を返します。引数で指定された日付の妥当性をチェックします。日付が 以下のようになっていれば妥当であると判断されます。

  • 年が0から32767の間であること。

  • 月が1から12の間であること。

  • dayが指定された月(month) の日数以内に収まること。うるう年(year) も考慮の対象となります。


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:
<PRE>
$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
}
</PRE>



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:

<pre>
&lt;?php

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

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



crazydude@mail.ru
06-May-2000 04:38
What is this:

checkdate("01","01",";");

The above command returns true. I'm wrong?



colin@candyforks.org
04-Jul-2000 08:22
I'm glad to see the people writing php know that feb. 29, 2100 is not a leap year!


colin@candyforks.org
04-Jul-2000 08:24
Um, ixnay the "Feb. 29" on that last note. :)


 About Notes


Previous page
 日付/時刻
 Updated
Sat, 12 Aug 2000
date 
Next page





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.