nicoschuck
nicoschuck

Reputation: 199

PHPExcel date to string

How i cant use the date from an excel. I use a for loop to output the file

echo $sheet -> getCellByColumnAndRow($j,$i)->getValue();

But the output looks like that:

 Date  |  Name
---------------
425831 |  Peter
425831 |  Nils

How i get something like that 2016-08.01?

Upvotes: 4

Views: 6275

Answers (1)

Philip
Philip

Reputation: 105

What you are getting is seconds from 1970. Try something similar to this, as mentioned in this answer:

$cell = $excel->getActiveSheet()->getCell('B' . $i);
$InvDate= $cell->getValue();
if(PHPExcel_Shared_Date::isDateTime($cell)) {
    $InvDate = date($format, PHPExcel_Shared_Date::ExcelToPHP($InvDate));
}

You can however also just convert it in PHP with this:

date('Y-m-d',PHPExcel_Shared_Date::ExcelToPHP($sheet -> getCellByColumnAndRow(1,12)->getValue()));

Upvotes: 1

Related Questions