I have an xlsx file that I upload to my web app and parse using PHP and PHPSpreadsheet. So far, I'm able to parse dates given that they're just the date, no time.
Here's the code I use:
$date_of_birth = PhpOfficePhpSpreadsheetSharedDate::excelToDateTimeObject($entry[5]);
$date_of_birth = $date_of_birth->format("Y-m-d");
Where $entry
is an array of data that represents one row in the excel file I have. Kindly note that I use getFormattedValue()
instead of getValue()
.
However, when I encounter something that has a timestamp, for example 7/18/1983 12:00:00 AM
, I get the output 1900-01-07
. For comparison, when I get a date like 12/6/14
, the output is 2014-12-06
, which is correct.
I'm not quite sure what I should do here as PhpSpreadsheet has very sparse documentation when it comes to this.
I can certainly just trim off the timestamp value and just have the script convert the date part, but I'm hoping to not have to resolve to that.
question from:
https://stackoverflow.com/questions/65932036/php-phpspreadsheet-not-converting-a-date-time-stamp-properly 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…