note 55110 added to function.date

From: Date: Tue, 26 Jul 2005 00:22:10 +0000
Subject: note 55110 added to function.date
Groups: php.notes 
Request: Send a blank email to php-notes+get-92436@lists.php.net to get a copy of this message
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; } ---- Manual Page -- http://www.php.net/manual/en/function.date.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+55110 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+55110&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+55110&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+55110&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+55110&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+55110&report=yes&reason=non-english Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+55110&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+55110&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#92436) next »