Example #1
0
 /**
  * Convert a date/time string to Excel time
  *
  * @param    string    $dateValue        Examples: '2009-12-31', '2009-12-31 15:59', '2009-12-31 15:59:10'
  * @return    float|FALSE        Excel date/time serial value
  */
 public static function stringToExcel($dateValue = '')
 {
     if (strlen($dateValue) < 2) {
         return false;
     }
     if (!preg_match('/^(\\d{1,4}[ \\.\\/\\-][A-Z]{3,9}([ \\.\\/\\-]\\d{1,4})?|[A-Z]{3,9}[ \\.\\/\\-]\\d{1,4}([ \\.\\/\\-]\\d{1,4})?|\\d{1,4}[ \\.\\/\\-]\\d{1,4}([ \\.\\/\\-]\\d{1,4})?)( \\d{1,2}:\\d{1,2}(:\\d{1,2})?)?$/iu', $dateValue)) {
         return false;
     }
     $dateValueNew = \PHPExcel\Calculation\DateTime::DATEVALUE($dateValue);
     if ($dateValueNew === \PHPExcel\Calculation\Functions::VALUE()) {
         return false;
     }
     if (strpos($dateValue, ':') !== false) {
         $timeValue = \PHPExcel\Calculation\DateTime::TIMEVALUE($dateValue);
         if ($timeValue === \PHPExcel\Calculation\Functions::VALUE()) {
             return false;
         }
         $dateValueNew += $timeValue;
     }
     return $dateValueNew;
 }