Problem reading date

Topics: User Forum
Jul 13, 2012 at 9:25 AM
Edited Jul 13, 2012 at 9:54 AM


I have XLSX file and I am trying to read values from it and save in database.
It's working fine except on the field where I have date "6/25/2012" it reads it as 41085, why is that so? How to make it read as String?
Thank you for any help
Jul 13, 2012 at 4:51 PM

Dates in Excel are stored as the number of days since 31st December 1899 (or 1st January 1904 if using the Mac 1904 Calendar). That's what you see here ( 41085). The only thing that differentiates them from numbers is the format mask.

In addition to using the cell getFormattedValue() which applies the format masking to that number and returns the date as a string according to the format mask used, there are a whole host of helper functions described in section 3.2.3 of the Function Reference that allow you to convert between Excel timsetamps and PHP timestamps or DateTime objects

Jul 18, 2012 at 2:49 PM
Edited Jul 18, 2012 at 2:50 PM

Hello friend.

function date_decode($target, $format){
	return PHPExcel_Style_NumberFormat::toFormattedString($target,$format);
$expProposalDate = date_decode($objPHPExcel->getActiveSheet()->getCellByColumnAndRow($col,$row)->getValue(), 'DD-MM-YYYY');

Thank you MarkBaker