[英]Convert php date into excel number string
I need to convert a PHP date into an Excel number;我需要将 PHP 日期转换为 Excel 数字; for example, 2019-06-01
in PHP is 43617
in Excel.例如, 2019-06-01
中的 2019-06-01 是43617
中的 43617。
$Result
must be the same as if I did ($June_date - $Date_work)/365
in Excel. $Result
必须与 Excel 中的($June_date - $Date_work)/365
相同。
The code I've tried so far is below, but it doesn't work.到目前为止我尝试过的代码如下,但它不起作用。
$Date_work = ('2016-03-01');
$June_date = ('2019-06-01');
$Result = ($June_date - $Date_work);
echo "$Result";
$date = '2019-06-01';
$excelNumber = strtotime($date." UTC")/86400 + 25569;
echo $excelNumber; //43617
or alternatively with the DateTime extension dt :或者使用DateTime 扩展名 dt :
$excelNumber = dt::create($date,'UTC')->getMsTimeStamp();
For the difference in days you need not convert to excel-number对于天数的差异,您无需转换为 excel-number
$Date_work = '2016-03-01';
$June_date = '2019-06-01';
$diffDays = date_create($Date_work)->diff(date_create($June_date))->days;
//1187
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.