php - not getting date properly from the xls sheet -
i'm using ubuntu coding.,
i'm importing xls file data controller, in 1 field date, i've formatted cell date format, when imported data fine date field getting displayed number,
for eg: entered date 2013-05-10 showed me 39942
then after check thing i've changed format of cell number keeping date value showed me value 39942 same value got controller..! how can correct date after importing,
any regarding this..?
excel stores date/times serialized float timestamps, number of days since jan 1st 1900 (or jan 1st 1904, depending on windows or mac calendar), , remembering considers 1900 leap year.
taken directly phpexcel date handling code:
public static function exceltophp($datevalue = 0) { if (self::$excelbasedate == self::calendar_windows_1900) { $myexcelbasedate = 25569; // adjust spurious 29-feb-1900 (day 60) if ($datevalue < 60) { --$myexcelbasedate; } } else { $myexcelbasedate = 24107; } // perform conversion if ($datevalue >= 1) { $utcdays = $datevalue - $myexcelbasedate; $returnvalue = round($utcdays * 86400); if (($returnvalue <= php_int_max) && ($returnvalue >= -php_int_max)) { $returnvalue = (integer) $returnvalue; } } else { $hours = round($datevalue * 24); $mins = round($datevalue * 1440) - round($hours * 60); $secs = round($datevalue * 86400) - round($hours * 3600) - round($mins * 60); $returnvalue = (integer) gmmktime($hours, $mins, $secs); } // return return $returnvalue; } // function exceltophp() set self::$excelbasedate == self::calendar_windows_1900 necessary indicate excel base calendar you're using: windows 1900 or mac 1904
and if want php datetime object instead:
public static function exceltophpobject($datevalue = 0) { $datetime = self::exceltophp($datevalue); $days = floor($datetime / 86400); $time = round((($datetime / 86400) - $days) * 86400); $hours = round($time / 3600); $minutes = round($time / 60) - ($hours * 60); $seconds = round($time) - ($hours * 3600) - ($minutes * 60); $dateobj = date_create('1-jan-1970+'.$days.' days'); $dateobj->settime($hours,$minutes,$seconds); return $dateobj; } // function exceltophpobject()
Comments
Post a Comment