2

I have this code for parsing date from excel cell and post it using json

the date on excel

using format dd/mm/yyyy

| column G |

|13/12/2020|

mycode

//start loop excel from 2nd row. Row 1 is title row
    for ($j=2; $j < $lastRow; $j++ ){
      ...
      'mr_submit_target' => date('Y-m-d H:i:s', PHPExcel_Shared_Date::ExcelToPHP($objWorksheet->getCell('G'.$j)->getValue())),
}

the result

"mr_submit_target": "1900-01-04 07:20:00", this is absolutely wrong based on excel data

my goal

to add H:i:s for my date from = "2020-12-13" to "2020-12-13 00:00:00" the exact time is not very important, but the server only can post using format Y-m-d H:i:s, thats why on my code i add 'H:i:s'

pramudityad
  • 57
  • 1
  • 8
  • Make a `strtotime(PHPExcel_Shared_Date::ExcelToPHP($objWorksheet->getCell('G'.$j)->getValue())` and the @user3783243 is pointing to the right answer. – Serghei Leonenco Apr 09 '20 at 05:15

1 Answers1

2

you should convert date string to time try this one

for ($j=2; $j < $lastRow; $j++ )
{ 
      'mr_submit_target' => date('Y-m-d H:i:s', strtotime(PHPExcel_Shared_Date::ExcelToPHP($objWorksheet->getCell('G'.$j)->getValue())),
}

I hope you got answered question | Happy coding ;)

Adeel Ahmed Baloch
  • 672
  • 2
  • 7
  • 15