Home>

Using PHPExcel, we are converting from xlsx to csv file.

When converting date type data, the converted value will change depending on the date delimiter.
I want to unify the output format of the converted date format to'yyyy-mm-dd'.

Corresponding source code
  • xlsx → csv conversion process
$reader = PHPExcel_IOFactory :: createReader ('Excel2007');
$book = $reader->load ("./hoge.xlsx");// xlsx file path to csv
$writer = PHPExcel_IOFactory :: createWriter ($book,'CSV')->setDelimiter (','));
$writer->save ("./hoge.csv");
  • xlsx sample and csv converted value
date
2020-12-31 // (Hyphen delimited) → 2020-12-31
2020/12/31 // (slash delimited) → 12-31-20
date
2020-12-31
12-31-20
What I tried
  • I thought it depends on the locale setting of the server, so I added the following code before the conversion process mentioned above, but the result did not change ...
setlocale (LC_ALL,'ja_JP.UTF-8');
Supplementary information (FW/tool version, etc.)

PHPExcel (1.7.4)
PHP (5.6.40)