PHP
downloads | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

date_create> <날짜/시간
Last updated: Sun, 25 Nov 2007

view this page in

checkdate

(PHP 4, PHP 5)

checkdate — 그레고리안력 날짜를 확인합니다.

설명

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

주어진 날짜가 유효하면 TRUE를, 유효하지 않으면 FALSE를 반환합니다. 각 인자가 구성하는 날짜의 유효성을 확인합니다. 다음과 같은 날짜가 유효합니다.

  • year는 1 이상 32767 이하
  • month는 1 이상 12 이하
  • Day 는 주어진 month 가 허용하는 일수입니다. 윤년 (Leaf year )도 고려합니다.

Example#1 checkdate() 예제

<?php
var_dump
(checkdate(12312000));
var_dump(checkdate(2292001));
?>

위 예제의 출력:

bool(true);
bool(false);

참고: mktime(), strtotime().



date_create> <날짜/시간
Last updated: Sun, 25 Nov 2007
 
add a note add a note User Contributed Notes
checkdate
el dot vartauy__ at t__gmail dot com
29-Feb-2008 10:18
for funny leap year detection:
<?php
function is_leap($year=NULL) {
    return
checkdate(2, 29, ($year==NULL)? date('Y'):$year); // true if is a leap year
}
?>
wasile_ro[at]yahoo[dot]com
08-Oct-2007 07:30
here's a cool function to validate a mysql datetime:

function isValidDateTime($dateTime)
{
    if (preg_match("/^(\d{4})-(\d{2})-(\d{2}) ([01][0-9]|2[0-3]):([0-5][0-9]):([0-5][0-9])$/", $dateTime, $matches)) {
        if (checkdate($matches[2], $matches[3], $matches[1])) {
            return true;
        }
    }

    return false;
}
jens wittmann
28-Aug-2007 08:29
for checking the rime use this:

function checktime($hour, $minute) {
    if ($hour > -1 && $hour < 24 && $minute > -1 && $minute < 60) {
        return true;
    }
}
brenig code
14-Aug-2007 11:21
<?php

/**
* check a date combo of the 2
*/
function checkData($date)
{
    if (!isset(
$date) || $date=="")
    {
        return
false;
    }
  
    list(
$dd,$mm,$yy)=explode("/",$date);
    if (
$dd!="" && $mm!="" && $yy!="")
    {
    if (
is_numeric($yy) && is_numeric($mm) && is_numeric($dd))
        {
            return
checkdate($mm,$dd,$yy);

        }
    }  
    return
false;

}
?>
a34 at yahoo dot com
09-Jul-2007 05:21
checkData function posted below does not consider a date entered such as 03/27c/2000.   The c will cause it to crash.  Here is the fix.

function checkData($mydate) {
      
    list($yy,$mm,$dd)=explode("-",$mydate);
    if (is_numeric($yy) && is_numeric($mm) && is_numeric($dd))
    {
        return checkdate($mm,$dd,$yy);
    }
    return false;           
}
manuel84**at**mp4**dot**it
04-Dec-2006 07:49
If you have a date like this gg/mm/aaaa and you'd like to verify that it is in the Italian Format you can use a function like this.
For other date format you can take this code and simply modify the list and explode line
<?php
/**
* check a date in the Italian format
*/
function checkData($date)
{
    if (!isset(
$date) || $date=="")
    {
        return
false;
    }
   
    list(
$dd,$mm,$yy)=explode("/",$date);
    if (
$dd!="" && $mm!="" && $yy!="")
    {
        return
checkdate($mm,$dd,$yy);
    }
   
    return
false;
}
?>

date_create> <날짜/시간
Last updated: Sun, 25 Nov 2007
 
 
show source | credits | stats | sitemap | contact | advertising | mirror sites