Delicious Bookmark this on Delicious Share on Facebook SlashdotSlashdot It! Digg! Digg



PHP : Function Reference : Date and Time Functions : checkdate

checkdate

Validate a Gregorian date (PHP 4, PHP 5)
bool checkdate ( int month, int day, int year )

Example 439. checkdate() example

<?php
var_dump
(checkdate(12, 31, 2000));
var_dump(checkdate(2, 29, 2001));
?>

The above example will output:

bool(true)
bool(false)

Code Examples / Notes » checkdate

manuel84**at**mp4**dot**it

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;
}
?>


wasile_ro

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;
}


daniel

Hello, here is simple function to get number of days in month:
function getNumberOfDays($year, $month) {
$day = 1;
while(checkdate($month,$day,$year))
$day++;
return $day-1;
}
Dan


anonymous

For daniel at mejta dot net
Here is an even simpler and more efficient way of getting the number of days in a month :
$month = 11;
$year = 2007;
$daysinmonth = date("t", mktime(0, 0, 0, $month, 1, $year));


jens wittmann

for checking the rime use this:
function checktime($hour, $minute) {
   if ($hour > -1 && $hour < 24 && $minute > -1 && $minute < 60) {
       return true;
   }
}


a34

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;
}


brenig code

<?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;
}
?>


Change Language


Follow Navioo On Twitter
checkdate
date_create
date_date_set
date_default_timezone_get
date_default_timezone_set
date_format
date_isodate_set
date_modify
date_offset_get
date_parse
date_sun_info
date_sunrise
date_sunset
date_time_set
date_timezone_get
date_timezone_set
date
getdate
gettimeofday
gmdate
gmmktime
gmstrftime
idate
localtime
microtime
mktime
strftime
strptime
strtotime
time
timezone_abbreviations_list
timezone_identifiers_list
timezone_name_from_abbr
timezone_name_get
timezone_offset_get
timezone_open
timezone_transitions_get
eXTReMe Tracker