Processing of Excel Date Field reading with excelreader in PHP

Source: Internet
Author: User

Excelreader is easy to use. I believe many PHP students need to use it to import data from Excel to the database, because it is easy to use, let's see his example.


However, when importing a date field from an Excel file, the problem arises. The first problem is the time zone and the format. I read the "d/M/y" format from Excel, and I usually use the "Y-m-d" format in MySQL. The conversion format is relatively easy. In/spreadsheet_excel_reader/EXCEL/reader. php


VaR $ dateformats = array (0xe => "d/M/Y", 0xf => "D-M-Y", 0x10 => "D-M ", 0x11 => "M-Y", 0x12 => "H: I a", 0x13 => "H: I: s ", 0x14 => "H: I", 0x15 => "H: I: s", 0x16 => "d/M/y h: I ", 0x2d => "I: s", 0x2e => "H: I: s", 0x2f => "I: S. s "); */change to VaR $ dateformats = array (0xe =>" Y-m-d ", 0xf =>" Y-m-d ", 0x10 => "M-d", 0x11 => "Y-M", 0x12 => "H: I a", 0x13 => "h: i: s a ", 0x14 =>" H: I ", 0x15 =>" H: I: s ", 0x16 => "Y-m-d h: I", 0x2d => "I: s", 0x2e => "H: I: s ", 0x2f => "I: S. s ");


$ Ifile = $ _ Get ['ifile '];
$ Upfile_type = strtolower (pathinfo ($ ifile, pathinfo_extension ));
If ($ upfile_type! = 'Xls '){
$ Mess = "{success: false, message: 'the file type you selected is not a valid Excel file! '}";
$ Mess = iconv ("gb2312", "UTF-8 // ignore", $ mess );
Echo $ mess;

Require_once '../excelreader/reader. php ';

// Excelfile ($ filename, $ encoding );
$ DATA = new spreadsheet_excel_reader ();
// Set output encoding.
$ Data-> setoutputencoding ('cp936 ');

$ Data-> Read ($ ifile );

Error_reporting (e_all ^ e_notice );


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.