note 96801 modified in function.mktime by thiago
| From: | thiago@php.net | Date: | Thu, 18 Mar 2010 02:49:39 +0000 |
| Subject: | note 96801 modified in function.mktime by thiago | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-167161@lists.php.net to get a copy of this message | ||
Proper way to convert Excel dates into PHP-friendly timestamps using mktime():
<?php
// The date 6/30/2009 is stored as 39994 in Excel
$days = 39994;
// But you must subtract 1 to get the correct timestamp
$ts = mktime(0,0,0,1,$days-1,1900);
// So, this would then match Excel's representation:
echo date("m/d/Y",$ts);
?>
Excel uses "number of days since Jan. 1, 1900" to store its dates. It also treats 1900 as
a leap year when it wasn't, thus there is an extra day which must be accounted for in PHP (and
the rest of the world). Subtracting 1 from Excel's number will fix this problem.
Thanks to http://www.ozgrid.com/Excel/ExcelDateandTimes.htm
for the details.
--was--
Proper way to convert Excel dates into PHP-friendly timestamps using mktime():
// The date 6/30/2009 is stored as 39994 in Excel
$days = 39994;
// But you must subtract 1 to get the correct timestamp
$ts = mktime(0,0,0,1,$days-1,1900);
// So, this would then match Excel's representation:
echo date("m/d/Y",$ts);
Excel uses "number of days since Jan. 1, 1900" to store its dates. It also treats 1900 as
a leap year when it wasn't, thus there is an extra day which must be accounted for in PHP (and
the rest of the world). Subtracting 1 from Excel's number will fix this problem.
Thanks to http://www.ozgrid.com/Excel/ExcelDateandTimes.htm
for the details.
http://php.net/manual/en/function.mktime.php