Beispiel #1
0
 private function get_sql_date($date_value)
 {
     return DateTool::date_to_sql($date_value);
 }
Beispiel #2
0
 public static function datetime_to_sql($date, $locale = null, $force_datetime = false)
 {
     $date = trim($date);
     $format = DateTool::get_datetime_format($locale);
     /*
      * Check if the $date should be parsed as a date and not a datetime
      */
     if (!$force_datetime && stripos($format, ' ') !== false && stripos($date, ' ') === false) {
         return DateTool::date_to_sql($date, $locale);
     } else {
         if ($force_datetime && stripos($date, ' ') === false) {
             $date .= ' 00:00:00';
         }
         $format = str_replace('Y', '%Y', $format);
         $format = str_replace('m', '%m', $format);
         $format = str_replace('d', '%d', $format);
         $format = str_replace('H', '%H', $format);
         $format = str_replace('i', '%M', $format);
         $format = str_replace('s', '%S', $format);
         $date_array = strptime($date, $format);
         if ($date_array !== false) {
             $day = sprintf("%02d", $date_array['tm_mday']);
             $month = sprintf("%02d", $date_array['tm_mon'] + 1);
             $year = 1900 + $date_array['tm_year'];
             $hour = sprintf("%02d", $date_array['tm_hour']);
             $min = sprintf("%02d", $date_array['tm_min']);
             $sec = sprintf("%02d", $date_array['tm_sec']);
             return $year . '-' . $month . '-' . $day . ' ' . $hour . ':' . $min . ':' . $sec;
         } else {
             return null;
         }
     }
 }