-1

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.

halfer
  • 19,824
  • 17
  • 99
  • 186
Braham Dev Yadav
  • 363
  • 1
  • 4
  • 13
  • user need to view your `php` code add your code like [this](http://stackoverflow.com/q/27352322/3836908) – sanoj lawrence Jan 09 '15 at 08:28
  • 1
    Perhaps a timezone issue; but without more information, all we can do is guess – Mark Baker Jan 09 '15 at 08:31
  • @Naruto: i have updated the question with useful informations, please check if you can find, why the excel reader adds 1 day to the output. – Braham Dev Yadav Jan 09 '15 at 09:27
  • Please post (the relevant part of) your code. But I do like @MarkBaker's suspicion of time zone. Try running it at different times of day & see what happens. – Mawg says reinstate Monica Jan 09 '15 at 09:37
  • If it's only a CSV file, why not simply use PHP's built-in fgetcsv() function; then you have complete control on every element of the data – Mark Baker Jan 09 '15 at 09:41
  • @MarkBaker: it is .xls format, and for .xls i am using this code. and for .CSV i am using that fgetscsv(). Actually i have to work on both formats. and the error is with Date only, other working fine. Thanks for other suggestions, i will try at different time also to check if it is timezone issue – Braham Dev Yadav Jan 09 '15 at 11:49
  • Does Spreadsheet_Excel_Reader() provide an option to return the Excel serialized timestamp? Or does it only ever return a "formatted" date string value? If the latter, you may need to set the PHP timezone to UST before loading the file.... this is something that other libraries like PHPExcel do automatically, rather than trusting to the settings on the server – Mark Baker Jan 09 '15 at 11:52

1 Answers1

0

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.

halfer
  • 19,824
  • 17
  • 99
  • 186
Braham Dev Yadav
  • 363
  • 1
  • 4
  • 13