|
|
|
<?
// 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="-./ ";
$p1 = strtok($idate,$token);
$p2 = strtok($token);
$p3 = strtok($token);
$p4 = strtok($token);
$date="";
$y=""; $m=""; $d="";
// check 'd.m.y'
if (($p1>0 && $p1<32) &&
($p2>0 && $p2<13) &&
($p3>32))
{
$y=$p3;
$m=$p2;
$d=$p1;
}
// check 'y.m.d'
if ($y == "" &&
($p1>32) &&
($p2>0 && $p2<13) &&
($p3>0 && $p3<32))
{
$y=$p1;
$m=$p2;
$d=$p3;
}
// check 'd.m'
if ($y == "" &&
($p3=="") &&
($p2>0 && $p2<13) &&
($p1>0 && $p1<32))
{
$y=date("Y");
$m=$p2;
$d=$p1;
}
// check 'd'
if ($y == "" &&
($p3=="") &&
($p2=="") &&
($p1>0 && $p1<32))
{
$y=date("Y");
$m=date("m");
$d=$p1;
}
// add 1900 or 2000 to year
if ($y!="" && $y<=99)
{
if ($y>=70) $y = $y + 1900;
if ($y<70) $y = $y + 2000;
}
if ($y!="")
{
if (checkdate($m, $d, $y))
$date="$y-$m-$d";
}
return $date;
}
?>
|
|
| Finding the day of the week for a specific date.
Categories : PHP, Databases, MySQL, Date Time | | | mysql date/time converters Categories : PHP, MySQL, Databases, Date Time | | | A php function to convert a mySQL timestamp(10) to a european readable format Categories : MySQL, Date Time, PHP, Databases | | | Data Retrieve from Mysql using AJAX with PHP Categories : PHP, AJAX, Date Time, Databases, MySQL | | | Simple function to return the number of days in a time span between 2 given dates. Categories : PHP, Date Time, MySQL, Databases | | | Phorum, MySQL, Language, UK date format, MySQL UK Date format Categories : PHP, Date Time, Strings, MySQL, Databases | | | List people whose birthdays fall on the current Day and Month
Categories : Databases, Date Time, MySQL, PHP | | | In Mysql, the 'datetime' data type is used to store date that looks like '2007-10-16 16:26:30'. we are going to design a function called mysqldate() that takes a mysql date and output format as input and outputs a well formated date. Categories : PHP, Date Time, Databases, MySQL | | | This program allows you to upload an ODBC ressource - i.e. an MS-Access database to a MySQL server. Categories : Databases, MySQL, Complete Programs, PHP, Databases | | | Simple conversion functions to change MySQL dates to arrays, arrays to MySQL dates.
Categories : PHP, Arrays, Date Time, Databases, MySQL | | | Count how many weeks in the month have a specified day, such as Mon, Tue, etc. Var avail - number of days - first day name of the month, occurrences of Sun, occurrences of Mon, etc. Allows you to calculate number of working hours exclude Holidays. Categories : Calendar, Date Time, PHP, Databases, MySQL | | | formating MySQL Timestamp to get a propper Output.
related : Timestamp, ereg_replace, mysql, substr Categories : MySQL, PHP, Date Time, Databases | | | How to Insert a Date Format Into MySQL from PHP Categories : PHP, Databases, MySQL, Date Time, Beginner Guides | | | bookmarker - PHP, PHPLIB, MySQL WWW based bookmark manager Categories : MySQL, PHP, MySQL, Complete Programs, Databases | | | This is Yet Another Sql Abstraction Library. Include it in your script and you can use the most important SQL functions without worrying about the SQL backend. Categories : Databases, PHP, ODBC, MySQL, PostgreSQL | |
| | | | 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="-./ ";
$p1 = strtok($idate,$token);
$p2 = strtok($token);
$p3 = strtok($token);
$p4 = strtok($token);
if ( $p3=="" ) {
$p3=date("Y");
if ( $p2=="" ) $p2=date("m");
}
// add $p1y and $p3y in year range
$p1y = $p1;
if ( $p1y<=99 ) { if ( $p1y<70 ) $p1y += 2000; else
$p1y += 1900; }
$p3y = $p3;
if ( $p3y<=99 ) { if ( $p3y<70 ) $p3y += 2000; else
$p3y += 1900; }
// check 'd.m.y'
if ( checkdate($p2, $p1, $p3y) ) return mktime
(0,0,0,$p2, $p1, $p3y);
// check 'm.d.y'
elseif ( checkdate($p1, $p2, $p3y) ) return mktime
(0,0,0,$p1, $p2, $p3y);
// check 'y.m.d'
elseif ( checkdate($p2, $p3, $p1y) ) return mktime
(0,0,0,$p2, $p3, $p1y);
return -1;
}
?>
| | | | 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;
}
| |
|
|
|