PHP parse date column from excel sheet (CSV)

浪子不回头ぞ 提交于 2019-12-08 11:42:56

问题


I created CSV file having date field in format 12-08-2018. When I opened csv file in Excel sheet it displays and saves in format 12/AUG/2018 to file.

When I am trying to parse it gives me wrong:

<?php
     echo date('Y-m-d',strtotime('12/AUG/2018')); // 1969-12-31
?> 

So, What could be the best way to handle parsing of date coming form excel sheet.


回答1:


Use createFromFormat function

$date = DateTime::createFromFormat('d/M/Y', '12/AUG/2018');
echo $date->format('Y-m-d'); // 2018-08-12


来源:https://stackoverflow.com/questions/51896900/php-parse-date-column-from-excel-sheet-csv

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!