protected function getDateTimeWithOptionalFormat($format, $value) { $date = DateTime::createFromFormat($format, $value); if ($date) { return $date; } try { return new DateTime($value); } catch (\Exception $e) { return; } }