0

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'),
seph roth
  • 25
  • 6
  • 1
    What do you want as *null dates*? 1970-0101 is start of epoch in Unix (and so in many system which derived from it), so 0 is that date. Just filter out the dates with 0, and put what you want, and format only dates with a positive number. – Giacomo Catenazzi Sep 19 '22 at 09:36

1 Answers1

0

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,
IT goldman
  • 14,885
  • 2
  • 14
  • 28