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
}
?>
checkdate
(PHP 4, PHP 5)
checkdate — Waliduje datę gregoriańską
Opis
bool checkdate
( int $miesiąc
, int $dzień
, int $rok
)
Zwraca TRUE, jeśli podana data jest prawdziwa lub FALSE w przeciwnym przypadku. Sprawdza prawdziwość daty podanej jako argument. Prawdziwość daty badana jest za pomocą reguł:
- rok zawiera się pomiędzy 1 i 32767 włącznie
- miesiąc zawiera się pomiędzy 1 i 12 włącznie
- dzień zawiera się we właściwej dla danego miesiąca liczbie dni. Lata przestępne są brane pod uwagę.
Example #1 checkdate() przykład
<?php
var_dump(checkdate(12, 31, 2000));
var_dump(checkdate(2, 29, 2001));
?>
Powyższy przykład wyświetli:
bool(true) bool(false)
Patrz także mktime() i strtotime().
checkdate
el dot vartauy__ at t__gmail dot com
29-Feb-2008 07:18
29-Feb-2008 07:18
wasile_ro[at]yahoo[dot]com
08-Oct-2007 04:30
08-Oct-2007 04: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 05:29
28-Aug-2007 05: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 08:21
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
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.
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
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;
}
?>
