从Excel中的PHP解析浮点数到年月日时布尔(假)结果

问题描述 投票:0回答:1

我必须从我的更改Excel格式的日期在DB上传。在Excel中,该行已经在日期格式。

当我调试行,日期的结果是浮置(43772)。然后,我尝试使用date_create_from_format改变格式。但现在,最新的结果始终为BOOL(假)或错误:DATE_FORMAT()预计参数1是DateTimeInterface,布尔给出。我这样的代码:

$column = 'A';
$row = 2;

while ($objexcel->getCell('A' . $row)->getValue() != '' && $objexcel 
>getCell('B' . $row)->getValue() != '') {

$tgl = $objexcel->getCell('D' . $row)->getValue();
$date = date_create_from_format('d/m/Y', $tgl);   /* here problem */
$update = date_format($date, 'Y-m-d');   /* here problem */

}

你能帮助我如何解决这个问题?

php phpexcel
1个回答
0
投票

这个日期值不是unix时间戳;这是一个MS Excel的系列化戳......你可以用getFormattedValue()代替getValue()阅读它作为一个格式化字符串(假设你读文件,readDataOnly设置为false;或者您也可以使用在ExcelToPHP()类可用的ExcelToPHPObject()PHPExcel_Shared_Date方法将其转换为Unix时间戳,或一个DateTime对象

© www.soinside.com 2019 - 2024. All rights reserved.