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

search for in the

date_add> <Date/Time Functions
Last updated: Fri, 22 Aug 2008

view this page in

checkdate

(PHP 4, PHP 5)

checkdateVaidar una fecha Gregoriana

Descripción

bool checkdate ( int $mes , int $dia , int $anyo )

Verifica la validez de la fecha formada por sus argumentos. Una fecha es considerada válida si cada parámetro es definido apropiadamente.

Lista de parámetros

mes

El mes es un valor entre 1 y 12 inclusive.

dia

El día es un valor entre el número permitido de días para el mes dado. Los anyo s bisiestos son tomados en cuenta.

anyo

El año es un valor entre 1 y 32767 inclusive.

Valores retornados

Devuelve TRUE si la fecha dada es válida; de lo contrario devuelve FALSE.

Ejemplos

Example #1 Ejemplo de checkdate()

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

El resultado del ejemplo seria:

bool(true)
bool(false)

Ver también



date_add> <Date/Time Functions
Last updated: Fri, 22 Aug 2008
 
add a note add a note User Contributed Notes
checkdate
saturn at ax dot com dot tw
26-Aug-2008 08:06
I wrote a simple function to converter datetime to UNIX timestamp. If the input time with error format, the function will return current timestamp.

function datetime2timestamp($datetime)
{
    $datetime = str_replace('-', ' ', $datetime);
    $datetime = str_replace('/', ' ', $datetime);
    $datetime = str_replace(':', ' ', $datetime);
    $array = explode(' ', $datetime);

    $year   = $array[0];
    $month  = $array[1];
    $day    = $array[2];
    $array[3] ? $hour   = $array[3] : $hour   = '00';
    $array[4] ? $minute = $array[4] : $minute = '00';
    $array[5] ? $second = $array[5] : $second = '00';
   
    if (preg_match("/^(\d{4}) (\d{2}) (\d{2}) ([01][0-9]|2[0-3]) ([0-5][0-9]) ([0-5][0-9])$/", "$year $month $day $hour $minute $second", $matches)) {
        if (checkdate($matches[2], $matches[3], $matches[1])) {
        return mktime(intval($hour), intval($minute), intval($second), intval($month), intval($day), intval($year));
        } else {
        return time();
        }       
    } else {
    return time();
    }
}
el dot vartauy__ at t__gmail dot com
29-Feb-2008 07: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 04:30
here's a cool function to validate a mysql datetime:

<?php
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 05:29
for checking the rime use this:

<?php
function checktime($hour, $minute) {
    if (
$hour > -1 && $hour < 24 && $minute > -1 && $minute < 60) {
        return
true;
    }
}
?>
brenig code
14-Aug-2007 08: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 02: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.

<?php
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 04: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_add> <Date/Time Functions
Last updated: Fri, 22 Aug 2008
 
 
show source | credits | stats | sitemap | contact | advertising | mirror sites