I'm importing an excel and store the data in a mysql database. Everything is working fine but the date is not importing correctly:
in excel the date is 'Saturday,December 1, 2016'
but after importing the result of this date is '42735'
Code
$this->load->library('excel');
$objPHPExcel = PHPExcel_IOFactory::load($excelfile);
$cell_collection = $objPHPExcel->getActiveSheet()->getCellCollection();
foreach ($cell_collection as $cell) {
$column = $objPHPExcel->getActiveSheet()->getCell($cell)->getColumn();
$row = $objPHPExcel->getActiveSheet()->getCell($cell)->getRow();
$data_value = $objPHPExcel->getActiveSheet()->getCell($cell)->getValue();
if ($row == 1) {
$header[$row][$column] = $data_value;
} else {
$arr_data[$row][$column] = $data_value;
}
}
//$data['header'] = $header;
$data['values'] = $arr_data;
foreach ($arr_data as $a=>$r ) {
$dob = $r['Date Of Birth'];
//this is returning 42735
I tried to convert this result in date but not succeeded. I'm using PHPExcel. Any suggestions how to fix this?
The easiest thing to do would be to change the format of your date column in Excel to the Mysql friendly fromat: YYYY-MM-DD.
Select your entire date column then in the Number menu on the Home tab select "More number formats". Then, in the Type field, type "YYYY-MM-DD" and click OK.
Then, if you ever want to echo/print your $dob in your original date format, you can try something like:
echo date("l, F d, Y", $dob)
Hope this helps.