note 32920 added to function.date

From: Date: Wed, 11 Jun 2003 01:23:22 +0000
Subject: note 32920 added to function.date
Groups: php.notes 
Request: Send a blank email to php-notes+get-50142@lists.php.net to get a copy of this message
Here's code that can extract the timestamp from a loosely formatted date string that a user inputs. It can deal with 'August 3rd, 2002' or '3 August 2002; or 2002 Aug <?php echo ExtractTimeStamp('August 3rd, 2002'); function ExtractTimeStamp($datestr) { $frags = explode(' ',$datestr); foreach ($frags as $frag) { switch (strtoupper(substr($frag,0,3))) { case "JAN": $ex_month=1; break; case "FEB": $ex_month=2; break; case "MAR": $ex_month=3; break; case "APR": $ex_month=4; break; case "MAY": $ex_month=5; break; case "JUN": $ex_month=6; break; case "JUL": $ex_month=7; break; case "AUG": $ex_month=8; break; case "SEP": $ex_month=9; break; case "OCT": $ex_month=10; break; case "NOV": $ex_month=11; break; case "DEC": $ex_month=12; break; } $ex_value = (int)$frag; if ( ($ex_value > 0) and ($ex_value < 32) ) { $ex_day = $ex_value; } if ($ex_value > 1900) { $ex_year = $ex_value; } } echo $ex_day,', ',$ex_month,', ',$ex_year,'<br>'; return mktime(0,0,0,$ex_month,$ex_day,$ex_year); } ?> ---- Manual Page -- http://www.php.net/manual/en/function.date.php Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+32920 Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+32920&report=yes Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+32920&report=yes

« previous php.notes (#50142) next »