0

I have obtained the value of my cell, with the following line:

date = $objPHPExcel->getActiveSheet()->getCell('U11')->getFormattedValue();

Since the cell stores a date, I had to use the method getFormattedValue(), because if used getCalculatedValue() returned a date type float.

My problem is that the data returned as a date is: 07-01-15, when in fact, the data that has excel in this column is: 01-07-2015

I have way to change the way returns that date?

Thanks!

urreta17
  • 183
  • 4
  • 20

1 Answers1

0

If PHPExcel can't return the date format using the format that you want, then you can force it to return either a Unix timestamp or a PHP DateTime object, and then format it however you want using native PHP functions:

$timestamp = PHPExcel_Shared_Date::ExcelToPHP(
    $objPHPExcel->getActiveSheet()->getCell('U11')->getCalculatedValue()
);
echo date('Y-m-d', $timestamp);

or

$dto = PHPExcel_Shared_Date::ExcelToPHPObject(
    $objPHPExcel->getActiveSheet()->getCell('U11')->getCalculatedValue()
);
echo $dto->format('Y-m-d');
Mark Baker
  • 209,507
  • 32
  • 346
  • 385