Example of php reading excel date data _ PHP Tutorial

Source: Internet
Author: User
Tags php excel
Example of php reading excel date data. Provides a read function: the code is as follows: excel date conversion function functionexcelTime ($ date, $ timefalse) {if (function_exists (GregorianToJD) {if (is_numeric ($ date )) {$ jd provides a read function:

The code is as follows:
// Excel date conversion function
Function excelTime ($ date, $ time = false ){
If (function_exists ('gregoriantojd ')){
If (is_numeric ($ date )){
$ Jd = GregorianToJD (1, 1, 1970 );
$ Gregorian = JDToGregorian ($ jd + intval ($ date)-25569 );
$ Date = explode ('/', $ gregorian );
$ Date_str = str_pad ($ date [2], 4, '0', STR_PAD_LEFT)
. "-". Str_pad ($ date [0], 2, '0', STR_PAD_LEFT)
. "-". Str_pad ($ date [1], 2, '0', STR_PAD_LEFT)
. ($ Time? "00:00:00 ":'');
Return $ date_str;
}
} Else {
$ Date = $ date> 25568? $ Date + 1: 25569;
/* There was a bug if Converting date before 1-1-1970 (tstamp 0 )*/
$ Ofs = (70*365 + 17 + 2) * 86400;
$ Date = date ("Y-m-d", ($ date * 86400)-$ ofs). ($ time? "00:00:00 ":'');
}
Return $ date;
}

Articles you may be interested in
  • Phpgeneration and reading excelfile (.csv) instance
  • PHP reading excelfile (.csv) instance introduction
  • PHPExcel instance program for generating and reading Excel files
  • PHP Excel reads excel files and imports them to the database
  • Drupal reads the Excel file and imports the code to the mysql database.
  • PHPExcel reads excel and imports mysql database code
  • PHPExcel reads excel and imports the database
  • POI reader EXCEL implementation program
  • Use phpexcel to read the excel code
  • Phpexcel Read excel document code

The expiration code is as follows // excel date conversion function excelTime ($ date, $ time = false) {if (function_exists ('gregoriantojd ') {if (is_numeric ($ date )) {$ jd...

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: info-contact@alibabacloud.com 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.