php Y-m-d add H:i:s

Viewed 103

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'

1 Answers

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 ;)

Related