phpphpexcelreader

Why PHP Excel reader output one more day from CSV?


I am using excel/reader.php to read the CSV file and get the data.

The date field in CSV have value: 20/10/2014

Customer Name    Date
Lorem Spem       20/10/14

and when I print this after reading the CSV using PHP:

        $file_name = $_FILES['file']['tmp_name'];
        $library_path = getcwd().'/application/libraries/excel/reader.php';
        require_once $library_path;
        $excel = new Spreadsheet_Excel_Reader();
        $excel->setOutputEncoding('CP1251');
        $status = $excel->read($file_name);
        $totalSheets = count($excel->sheets);
        for($sheetCount = 0 ; $sheetCount < $totalSheets ; $sheetCount++)
        {
            $excel_data = $excel->sheets[$sheetCount]['cells'];
            $totalRows = $excel->sheets[$sheetCount]['numRows'];
            print_r($excel_data);
        }

It gives the result: 21/10/2014

Array ( [1] => Lorem Spem [2] => 21/10/2014 )

I don't know why it add one day to the date from CSV.


Solution

  • I have found the code is correct: it was giving one day added to the date from Excel sheet on Local Host only.

    When I have uploaded this code to the Live Server, it is giving correct date.

    I think this is Time Zone issue again. As the CSV which I tried to read was made in Canada time zone, and I tried to read in India time zone, so the error of date shows.

    But when I uploaded the code to the live server of Canada, then it starts giving the correct date from the Excel Sheet.