note 111766 added to function.mktime
| From: | skinnepa at hotmail dot com | Date: | Tue, 26 Mar 2013 13:15:48 +0000 |
| Subject: | note 111766 added to function.mktime | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-194211@lists.php.net to get a copy of this message | ||
Convert Excel whacky-time to timestamp
function exceltoepoch($whackyexceltime) {
if (is_numeric($whackyexceltime)) {
// intify
$int_portion = (int)$whackyexceltime;
// get the decimals
$dec_portion = $whackyexceltime - $int_portion;
// $int portion is days since Jan 1, 1900.
$epoch = new DateTime('1900-01-01');
// remove 2 seems to be the magic number of days to remove.
$epoch->add(new DateInterval("P".($int_portion - 2)."D"));
// get the seconds that are left
$sec = ceil(86400 * $dec_portion);
// add the second to the epoch
$epoch->add(new DateInterval("PT".$sec."S"));
$ret = $epoch->getTimestamp();
unset($epoch);
//echo date("D, d M Y H:i:s", $ret) ."\n\n";
return $ret;
} else {
// probably not a whacky timestamp, lets try to guess it to
// an epoch and pray
$ts = strtotime($whackyexceltime);
//echo date("D, d M Y H:i:s", $ts)."\n\n";
return $ts;
}
}
----
Server IP: 69.147.83.199
Probable Submitter: 206.191.52.229
----
Manual Page -- http://php.net/manual/en/function.mktime.php
Edit -- https://master.php.net/note/edit/111766
Del: integrated -- https://master.php.net/note/delete/111766/integrated
Del: useless -- https://master.php.net/note/delete/111766/useless
Del: bad code -- https://master.php.net/note/delete/111766/bad+code
Del: spam -- https://master.php.net/note/delete/111766/spam
Del: non-english -- https://master.php.net/note/delete/111766/non-english
Del: in docs -- https://master.php.net/note/delete/111766/in+docs
Del: other reasons-- https://master.php.net/note/delete/111766
Reject -- https://master.php.net/note/reject/111766
Search -- https://master.php.net/manage/user-notes.php