<?php
//********************************************************************
function makeFullYear( $year )
{
if ( strlen( $year ) != 2 ) {return $year;}
$now_yyyy = date( 'Y' );
$now_yy = date( 'y' );
if ( $year > $now_yy ) {
$century = ((int)substr( $now_yyyy, 0, 2 )) - 1;
}
else {
$century = ((int)substr( $now_yyyy, 0, 2 ));
}
return $century. $year;
}
//********************************************************************
function ParseDate( $value, &$day, &$month, &$year )
{
$lvdate = preg_match (
'/^([0-9]{1,2})\.([0-9]{1,2})\.([0-9]{2}([0-9]{2})?)$/',
$value, $matches );
if ( !$lvdate ) {
$endate = preg_match (
'#^([0-9]{1,2})[/]([0-9]{1,2})[/]([0-9]{2}([0-9]{2})?)$#',
$value, $matches );
if ( !$endate ) { return FALSE; }
$month = $matches[1];
$day = $matches[2];
$year = $matches[3];
}
else
{
$day = $matches[1];
$month = $matches[2];
$year = $matches[3];
}
if ( strlen( $year ) == 2 ) {
$year = makeFullYear( $year );
}
return checkdate( $month, $day, $year );
}
//********************************************************************
// Function makes the quoted MySQL date value out of the
// given date value
//********************************************************************
function makeMySqlDateQ( $value )
{
if ( trim( $value ) == '' ) {return 'NULL';}
if ( ! ParseDate( $value, $day, $month, $year ) )
{
return "'0000-00-00'";
}
else {
return "'$year-$month-$day'";
}
}
?>