PHPExcel icon indicating copy to clipboard operation
PHPExcel copied to clipboard

Reading from Excel and change date format

Open tomkralik opened this issue 8 years ago • 1 comments

Hello, please help me. I read data from XLSX file. I get array, that contains datetime in format 31.10.2015 Into Excel file is save values as 31.10.2015.

Please, How Can I get date format 2015-10-31?

Have to I set anything in MS Excel file?

I try it with this code but can not.

$sheetData = $objPHPExcel->getActiveSheet()        // Format as date and time
                        ->getStyle('M:N')
                        ->getNumberFormat()
                        ->setFormatCode(\PHPExcel_Style_NumberFormat::FORMAT_DATE_YYYYMMDD2);

Thank you for your help

tomkralik avatar Nov 30 '15 09:11 tomkralik

Thanks for the ->setFormatCode(\PHPExcel_Style_NumberFormat::FORMAT_DATE_YYYYMMDD2); example. Thats what i needed.

I know this is old, but you might need to make sure you set in your start and end rows ->getStyle($colLetter . $startRow . ':' . $colLetter . $endRow)