I have an Excel file, where I have a date column. The date looks like "17.07.2020".
I'm using Laravel and Maatwebsite Excel import. When I'm saving the imported data to MySQL, the date in MySQL is always "1970-01-01".
Here is the code, which I have now:
return new Product([
.......
'discountBeginning' => date('Y-m-d', strtotime($row['discount_beginning'])
]);
I would like to format the date from Excel to "2020-07-17".
discountBeginningbeing stored in your database?$row['discount_beginning']? Looks like thestrtotime()call is the bug here, since it is just returning the Unix Epoch Time (1970-01-01). Perhaps$row['discount_beginning']contains a format thatstrtotime()is unable to parse?1970-01-01date. What really worked for me is$your_date = PhpOffice\PhpSpreadsheet\Shared\Date::excelToDateTimeObject($row['your_date']);from the comment section of this question. In the excel row, I got a string as2022-05-29(for example) and that worked!