Excel import to MySQL: Date inserted as 0000-00-00 -
i have used phpexcel library import excel file (.xlsx) , insert mysql. i'm facing 2 problems date field:
1- in excel sheet try change date format desired one. upon saving, cells show format need (yyyy/mm/dd)
when double-click edit them again change how before (mm/dd/yyyy)
.
2- when file imported mysql through phpexcel columns inserted correctly except date column inserts 0000-00-00
. format in excelsheet same in mysql enters zeros.
please help!
the value store in phpexcel excel serialized datetime value (a float, representing number of days since 1/1/1900 or 1/1/9004 depending on whether windows or mac calendar used). changing format changing way value displayed.
you either need know in advance whether cell contains date, or test using phpexcel_shared_date::isdatetime()
method, , convert appropriately. can either retrieve using getformattedvalue()
return value formatted string; or use built-in conversion functions convert unix timestamp (phpexcel_shared_date::exceltophp()
) or php datetime object (phpexcel_shared_date::exceltophpobject()
) can format using standard php date formatting functions before using in mysql insert/update statements.
Comments
Post a Comment