1

I have a CSV file containing date values. Eg. 3/1/2015

But with my current code

$rowData[$i][0][6] = date('Y-m-d', PHPExcel_Shared_Date::ExcelToPHP($upper[0][6]));

it reads it as 2036-02-09.

I know PHPExcel is best used with xls and xlsx, but my boss tells me to use a csv file for a file upload event. How can i get the correct date?

DonCallisto
  • 29,419
  • 9
  • 72
  • 100
Paul Ryan Lucero
  • 521
  • 1
  • 3
  • 16

1 Answers1

0

Try to reformat it with strtotime like this:

$rowData[$i][0][6] = date('Y-m-d', strtotime(PHPExcel_Shared_Date::ExcelToPHP($upper[0][6])));

Or for PHP 5

$datetime = PHPExcel_Shared_Date::ExcelToPHP($upper[0][6]); 
$d = DateTime::createFromFormat("d/m/Y", $datetime);
// Format it as you want
echo $d->format("d.m.Y H:i:s");
MatejG
  • 1,393
  • 1
  • 17
  • 26