note 103958 added to function.mktime

From: Date: Fri, 13 May 2011 15:41:53 +0000
Subject: note 103958 added to function.mktime
Groups: php.notes 
Request: Send a blank email to php-notes+get-179695@lists.php.net to get a copy of this message
Here is a couple functions I put together to transform a date into a timestamp. It will adjust to either a Year, Month, Date format or Month, Date, Year and can handle a '/' or a '-' separator or anything else you want to add to the $delimiter array. <?php function textSearch($mystring, $findme) { $pos = strpos($mystring, $findme); if ($pos !== false) { $val = true; } else{ $val = false; } return $val; } function multideliexplode ($delimiters,$mystring,$fields) { foreach ($delimiters as $delim) { $search = textSearch($mystring, $delim); if ($search) { $ary = explode($delim, $mystring, $fields); }} return $ary; } function datetoTS($date) { $delimiters = array('/', '-'); $list = multideliexplode($delimiters, $date, 3); if(checkdate($list[0], $list[1], $list[2])) { $newdate = mktime(0, 0, 0, $list[0], $list[1], $list[2]); } elseif(checkdate($list[2], $list[0], $list[1])) { $newdate = mktime(0, 0, 0, $list[2], $list[0], $list[1]); } else { die("Invalid Date: ". $list[0] . ", ".$list[1].", ".$list[2]); } return $newdate; } $DateTS = datetoTS($DateString); ?> ---- Server IP: 192.41.42.26 Probable Submitter: 208.104.125.69 ---- Manual Page -- http://www.php.net/manual/en/function.mktime.php Edit -- https://master.php.net/note/edit/103958 Del: integrated -- https://master.php.net/note/delete/103958/integrated Del: useless -- https://master.php.net/note/delete/103958/useless Del: bad code -- https://master.php.net/note/delete/103958/bad+code Del: spam -- https://master.php.net/note/delete/103958/spam Del: non-english -- https://master.php.net/note/delete/103958/non-english Del: in docs -- https://master.php.net/note/delete/103958/in+docs Del: other reasons-- https://master.php.net/note/delete/103958 Reject -- https://master.php.net/note/reject/103958 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#179695) next »