Home > Enterprise >  Imported excel null date inputted as 1970-01-01
Imported excel null date inputted as 1970-01-01

Time:09-29

I'm using phpoffice/phpspreadsheet as the packages. When im testing the function of importing excel into database. I noticed all the null dates are now 1970-01-01. How do I fix it? Following is the sample code.

'Registrant_date'=>\PhpOffice\PhpSpreadsheet\Shared\Date::excelToDateTimeObject($row['Registrant_date'])->format('Y-m-d'),

CodePudding user response:

As suggested in comments, compare date to zero.

$reg_date = \PhpOffice\PhpSpreadsheet\Shared\Date::excelToDateTimeObject($row['Registrant_date']);

'Registrant_date'=> date_timestamp_get($reg_date) ? $reg_date->format('Y-m-d') : null,
  • Related