note 55110 deleted from function.date by aidan
| From: | aidan@php.net | Date: | Sun, 31 Jul 2005 12:31:37 +0000 |
| Subject: | note 55110 deleted from function.date by aidan | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-92811@lists.php.net to get a copy of this message | ||
Note Submitter: darren dot nolan at gmail dot com
----
Hi All!!
The problem with Windows not supporting dates prior to 1970 was completely "S#@Ting" me.
As such, bati1927 pointed me in the right direction and I thank him SO much. To that note,
I've created two functions, one to store Data into MySQL in the correct format, and one to
Display the Data stored in MySQL. (The StoreDate Function is COMPLETELY based off bati1927's
work, I give him FULL credit).
The date format I've used is the MySQL Y-m-d, and the Good Ole Aussie Style of d/m/y. I hope
that anyone can edit this to suit their needs to overcome the problems with mkdate.
function StoreDate($input_date) {
$input_format = "d/m/Y";
preg_match("/^([\w]*)/i", $input_date, $regs);
$sep = substr($input_date, strlen($regs[0]), 1);
$label = explode($sep, $input_format);
$value = explode($sep, $input_date);
$array_date = array_combine($label, $value);
if (in_array('Y', $label)) {
$year = $array_date['Y'];
} elseif (in_array('y', $label)) {
$year = $year = $array_date['y'];
} else {
return false;
}
if (strlen($year)==2) {
/* We've been only been given the last two digits for the year */
if (intval($year)>30) {
/* If it's bigger than 30, than it must be 19** */
$year = "19" . $year;
} else {
$year = "20" . $year;
}
}
$output_date = $year . "-" . $array_date['m'] . "-" .
$array_date['d'];
return $output_date;
}
function DisplayDate($input_date) {
$newdate = mysql_query("SELECT Date_Format('$input_date',
'%d/%m/%Y')");
if (!$newdate) {
echo "Error occured";
exit();
}
$row = mysql_fetch_array($newdate, MYSQL_NUM);
$output_date = $row[0];
return $output_date;
}