note 83353 added to function.date

From: Date: Thu, 22 May 2008 03:37:42 +0000
Subject: note 83353 added to function.date
Groups: php.notes 
Request: Send a blank email to php-notes+get-139599@lists.php.net to get a copy of this message
The function below extracts any date time value basead in the string format. Returns an associative array with day,month,year,hour,min and seg separated. function ExtractDateTimeByFormat($strDateTime, $strFormat="dmYHis") { //extract the format $i = 0; $aFieldOrder = array(); $nFields = 0; $strExtraction = ""; while(isset($strFormat[$i])) { $strField = $strFormat[$i]; switch ( strtolower($strField) ) { case "D"; case "d"; $aFieldOrder[$nFields] = "d"; $nFields++; $strExtraction .= "%d"; if(isset($strFormat[$i+1])) { $strExtraction .= "%*1c"; } break; case "M"; case "m"; $aFieldOrder[$nFields] = "m"; $nFields++; $strExtraction .= "%d"; if(isset($strFormat[$i+1])) { $strExtraction .= "%*1c"; } break; case "y"; case "Y"; $aFieldOrder[$nFields] = "y"; $nFields++; $strExtraction .= "%4d"; if(isset($strFormat[$i+1])) { $strExtraction .= "%*1c"; } break; case "h"; case "H"; $aFieldOrder[$nFields] = "h"; $nFields++; $strExtraction .= "%d"; if(isset($strFormat[$i+1])) { $strExtraction .= "%*1c"; } break; case "i"; $aFieldOrder[$nFields] = "i"; $nFields++; $strExtraction .= "%d"; if(isset($strFormat[$i+1])) { $strExtraction .= "%*1c"; } break; case "S"; case "s"; $aFieldOrder[$nFields] = "s"; $nFields++; $strExtraction .= "%d"; if(isset($strFormat[$i+1])) { $strExtraction .= "%*1c"; } break; } $i++; } $aValues = array(); $aValues = sscanf($strDateTime,$strExtraction); return array_combine($aFieldOrder,$aValues); } ---- Server IP: 69.147.83.197 Probable Submitter: 201.1.64.243 ---- Manual Page -- http://www.php.net/manual/en/function.date.php Edit -- https://master.php.net/note/edit/83353 Del: integrated -- https://master.php.net/note/delete/83353/integrated Del: useless -- https://master.php.net/note/delete/83353/useless Del: bad code -- https://master.php.net/note/delete/83353/bad+code Del: spam -- https://master.php.net/note/delete/83353/spam Del: non-english -- https://master.php.net/note/delete/83353/non-english Del: in docs -- https://master.php.net/note/delete/83353/in+docs Del: other reasons-- https://master.php.net/note/delete/83353 Reject -- https://master.php.net/note/reject/83353 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#139599) next »