0

I set in my excell file for format date like 09/01/19 (dd/mm/yy)

my function to get format date in excell like this

$form = $sheet->getCellByColumnAndRow($j, $i)->getStyle()->getNumberFormat()->getFormatCode();

but when im try to call with format excell, the result is 0909/0101/1919

$vax = '2019-01-09 03:09:00'; $createDate = new DateTime($vax);
$vax = $createDate->format($form); }
Yan
  • 27
  • 1
  • 1
  • 6

2 Answers2

0

In php documentation you can see [here][1]

[1]: http://php.net/manual/en/datetime.format.php, it requires

$createDate->format($form); // in here you need to give ur format like this 'Y-m-d H:i:s'

but what you have done is giving it the format from ur excel like this 09/01/19 this does not recognize by the php method. so change the input for that function to 'Y-m-d H:i:s' format

$date = new DateTime('2000-01-01');
echo $date->format('Y-m-d H:i:s');

so change your mehtod like this

$createDate = new DateTime($vax);
$vax = $createDate->format('Y-m-d H:i:s');
ALPHA
  • 1,135
  • 1
  • 8
  • 18
0

MS Excel has its own date formatting masks that Microsoft created before PHP even existed - https://support.office.com/en-us/article/Format-a-date-the-way-you-want-8E10019E-D5D8-47A1-BA95-DB95123D273E - and which isn't the same as that used by PHP. If you use the getFormatCode() method in PHPExcel/PHPSpreadsheet, it will return the MS Excel format mask

Mark Baker
  • 209,507
  • 32
  • 346
  • 385