Parsing della data in PhpSpreadsheet
Sun un file excel che devo importare tramite PhpSpreadsheet, c'è un campo data.
Li per li non mi sono accorto che la data veniva caricata in maniera errata.
Girando ho visto che esistono due metodi per fare il giusto parsing di un campo date:
- excelToTimestamp -> che ritorna timestamp
- excelToDateTimeObject -> che ritorna un oggetto DateTime
Vediamo un esempio di entrambi (li metto insieme):
use PhpOffice\PhpSpreadsheet\Shared\Date;
$value = $worksheet->getCell('A1')->getValue();
$dt = Date::excelToTimestamp($value);
$value = $worksheet->getCell('A1')->getValue();
$dt = Date::excelToDateTimeObject($value);
A questo punto dovete solo scegliere quale formato vi serve e farne il parsing.
Enjoy!
php phpspreadsheet excel exceltotimestamp exceltodatetimeobject timestamp datetime
Commentami!