|
|
checkdate (PHP 3, PHP 4, PHP 5) checkdate -- Проверяет правильность даты по грегорианскому календарю Описаниеbool checkdate ( int month, int day, int year )
Возвращает TRUE если дата, заданная аргументами, является правильной;
иначе возвращает FALSE.
Дата считается правильной, если:
год в диапазоне от 1 до 32767 включительно
месяц в диапазоне от 1 до 12 включительно
day является допустимым номером дня для
месяца, заданного аргументом
month, принимая во внимание,что
year может задавать високосный год.
Пример 1. Пример использования функции checkdate() |
<?php
var_dump(checkdate(12, 31, 2000));
var_dump(checkdate(2, 29, 2001));
?>
|
Приведенный выше пример выведет:
|
См.также описание функций mktime() и strtotime().
Anonymous
26-Oct-2007 12:24
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));
daniel at mejta dot net
15-Oct-2007 07:57
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
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;
}
}
jens wittmann
28-Aug-2007 08:28
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
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
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;
}
?>
|