I’ve problem with read date value from import value (Excel) to mysql database. i’ve code as below :
$dataexcel[$i-3]['date_edit'] = date('m/d/Y', strtotime(trim($data['cells'][$i][25])));
i tried use strtotime
to define value from excel, but i’ve problem to save it into database, if my value in excel with excel date format is 1/1/2018
(it read as 1 Jan 2018, English time format), after i used my code above, it saved become 1970-01-01
it means 1 Jan 1970.
in another example,
i tried another input with date 2/1/2018
, it saved into database as 2018-02-02
.
from my samples above, in first there missmatch problem with year, then and in the 2nd sample missmatch problem come from date,
so how to declare date to solve my problem, if i want to save date format with simple way? if there any advice , please, thanks…
Advertisement
Answer
From your comment answer, you can modification some code like below :
$date = str_replace("/", ".", $data['cells'][$i][25]); $dates = date("Y-m-j", strtotime($date)); $dataexcel[$i-3]['date_edit'] = $dates;
$date still pick up from value without used strotime
, so date format didn’t read correctly…