L
L
Lomoson2014-07-02 12:48:05
PHP
Lomoson, 2014-07-02 12:48:05

How to set date format like "27.02.2014 15:58" in PHPExcel?

Can you please tell me how to set the format for dates like: "02/28/2014 00:07", "05/26/2014 21:22"?
On maxibazar.eu/mbm2/application/plugins/excel/Docume... there is no required format, but somehow you need to sort by column.
In Excel itself, this is (all formats)->type->DD.MM.YYYY h:mm

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
Oleg Krasnov, 2014-07-03
@Lomoson

It should work like this:

$page = $objPHPExcel->setActiveSheetIndex(0);
$page->setCellValue("A1", '27.02.2014 15:58');
$objPHPExcel->getActiveSheet()->getStyle('A1')->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_DATE_DATETIME);

The cell is given the desired format. And sorting in Excel works fine for me.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question