PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Wednesday, October 5, 2022

[FIXED] How can set format datetime [PHPExcel]

 October 05, 2022     datetime, excel, php, phpexcel     No comments   

Issue

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


Solution

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



Answered By - Leviathan
Answer Checked By - Candace Johnson (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing