Beispiel #1
0
 /**
  * Convert string to DateTime
  *
  * @param string $value
  * @param bool $midnight
  * @return DateTime
  */
 public static function createFromFormat($value, $format, $midnight = TRUE)
 {
     if ($value === null) {
         $now = new \DateTime();
         //because of php 5.3 I have to split it to two lines.
         $dt = $now->setTimestamp(0);
         //oldest date
     } else {
         $dt = date_create_from_format($format, $value);
     }
     if ($midnight) {
         $dt->setTime(0, 0, 0);
     }
     return $dt;
 }