Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel Excel import returning wrong date

Tags:

php

laravel

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".

like image 914
Jakub Kříž Avatar asked Oct 27 '25 14:10

Jakub Kříž


1 Answers

Try this

$date = new DateTime($row['discount_beginning']);
echo $date->format('d.m.Y');
like image 142
VIKAS KATARIYA Avatar answered Oct 30 '25 04:10

VIKAS KATARIYA