note 103958 deleted from function.mktime by danbrown

From: Date: Fri, 13 May 2011 15:43:26 +0000
Subject: note 103958 deleted from function.mktime by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-179697@lists.php.net to get a copy of this message
Note Submitter: jessier3 at gmail dot com ---- 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); ?>

« previous php.notes (#179697) next »