Waleed Khan
Waleed Khan

Reputation: 93

PHP parse date column from excel sheet (CSV)

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.

Upvotes: 0

Views: 602

Answers (1)

splash58
splash58

Reputation: 26153

Use createFromFormat function

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

Upvotes: 5

Related Questions