Days since 1900

喜夏-厌秋 提交于 2020-01-15 02:54:25

问题


I'm using data from Excel2007 as parsed by PHPExcel, and dates come out as days since 1900.

How can I convert to string of YYYY-MM-DD (or anything similar)?


回答1:


Or use

$phpDate = PHPExcel_Shared_Date::ExcelToPHP($cell->getCalculatedValue());

to convert an Excel/PHPExcel date to a PHP date/timestamp, and then use standard PHP date() function for formatting




回答2:


Something like this, should do the trick:

PHPExcel_Style_NumberFormat::toFormattedString($cell->getCalculatedValue(), 'YYYY-MM-DD');



回答3:


purely php

 $datetime1 = new DateTime('1900-01-01');
 $datetime2 = new DateTime(); // today
 $interval = $datetime1->diff($datetime2);
 $days=$interval->format('%a');
 $days+=2; // add boundary days
 echo $days;  // this is the number excel will use


来源:https://stackoverflow.com/questions/2988201/days-since-1900

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!