KwangKung
KwangKung

Reputation: 169

How can set format datetime [PHPExcel]

set format datetime with php and output excel

date_default_timezone_set('Asia/Bangkok');
$objPHPExcel->getActiveSheet()->SetCellValue('S1', 'Show DateTime');
$dateValue = PHPExcel_Shared_Date::PHPToExcel( strtotime('23-Apr-1989 17:05:50') );
$objPHPExcel->getActiveSheet()
    ->setCellValue('S2', $dateValue);
$objPHPExcel->getActiveSheet()
    ->getStyle('S2')
    ->getNumberFormat()
    ->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_DATE_YYYYMMDDSLASH);


but output

enter image description here



How can show data on Excel 23/04/1989 17:05:50 and excel type Date

Upvotes: 1

Views: 11459

Answers (1)

tyg
tyg

Reputation: 14815

You currently use the predefined constant PHPExcel_Style_NumberFormat::FORMAT_DATE_YYYYMMDDSLASH for your number format.

If you replace that by your desired format, everything should be ok: 'dd/mm/yyyy hh:mm:ss'

Also see the documentation for setFormatCode(): http://apigen.juzna.cz/doc/ouardisoft/PHPExcel/class-PHPExcel_Style_NumberFormat.html#_setFormatCode

Upvotes: 2

Related Questions