<?
// This function is made to check date-input from an HTML-form
// and bring it to the YYYY-MM-DD format that it can be
// insertet in a Date-Field of a MySQL-Table.
//
// Input-Formats can be:
// "d.m.y" or "y.m.d" or "d.m" or "d"
// if year or month and year are missing, these values are
// taken from the current date.
//
// When the result-String is empty, the date-input was wrong.
//
// Usage: $date_ok = input2date($date_from_form_field);
//
function input2date($idate)
{
$token="-./ ";
Slava Knyazhevsky wrote :39 <?
// int DateInput(string datestring)
// This function is made to check date-input from an
HTML-form
// and bring it to the Unix timestamp format that it can
be
// insertet in a date() function
//
// Input-Formats can be:
// "d.m.y" or "m.d.y" or "y.m.d" or "d.m" or "d"
// if year or month and year are missing, these values
are
// taken from the current date.
//
// When the result == -1, the date-input was wrong.
//
// Usage: $timestamp = DateInput
($date_from_form_field);
//
function DateInput($idate) {
$token="-./ ";
Christian Weinert wrote :456
The function won`t work for Years smaller than 33. If you enter `16.09.00` the function returns nothing.
That`s because in the check for `d.m.y`, `16.09.00` returns $p3=0 and the clause is $p3>32.
Change the function as below, substituting `>32` with `>=0` and it will work perfectly!
// check `d.m.y`
if (($p1>0 && $p1<32) &&
($p2>0 && $p2<13) &&
($p3>=00)) //change this one
{
$y=$p3;
$m=$p2;
$d=$p1;
}
// check `y.m.d`
if ($y == "" &&
($p1>=00) && //and this one
($p2>0 && $p2<13) &&
($p3>0 && $p3<32))
{
$y=$p1;
$m=$p2;
$d=$p3;
}