note 43759 added to function.strtotime

From: Date: Fri, 02 Jul 2004 11:42:46 +0000
Subject: note 43759 added to function.strtotime
Groups: php.notes 
Request: Send a blank email to php-notes+get-72319@lists.php.net to get a copy of this message
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); ---- Manual Page -- http://www.php.net/manual/en/function.strtotime.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+43759 Delete -- http://master.php.net/manage/user-notes.php?action=delete+43759&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+43759&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#72319) next »