note 43759 deleted from function.strtotime by tomsommer
| From: | tomsommer@php.net | Date: | Thu, 09 Sep 2004 20:27:38 +0000 |
| Subject: | note 43759 deleted from function.strtotime by tomsommer | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-76355@lists.php.net to get a copy of this message | ||
Note Submitter: me at samscam dot co dot uk
----
Strtotime may parse English dates, but British it ain't. The typical colloquial date format in
the UK is dd/mm/yy (rather than mm/dd/yy).
Here is a crude bit of code to swap the fragments round prior to parsing with strtotime - for sites
aimed squarely at brits naturally.
// Taking the date from web form input
$ourdate=stripslashes($_REQUEST['ourdate']);
// Swap round dd and mm for British-style dates if necessary
// Assuming forward slashes are used for the delimiter
if (preg_match("/\d{1,2}\/\d{1,2}(\/\d{2,4})?/",$ourdate)){
$temparr=explode("/",$ourdate);
$temparr=$temparr[1]."/".$temparr[0]; // re-assemble the first part of the date
if ($temparr[2]){$ourdate.="/".$temparr[2];} // Add the year if used
}
$parseddate=strtotime($ourdate);