Overtrue\Validation\Validator::getDateTimeWithOptionalFormat PHP Method

getDateTimeWithOptionalFormat() protected method

Get a DateTime instance from a string.
protected getDateTimeWithOptionalFormat ( string $format, string $value ) : DateTime | null
$format string
$value string
return DateTime | null
    protected function getDateTimeWithOptionalFormat($format, $value)
    {
        $date = DateTime::createFromFormat($format, $value);
        if ($date) {
            return $date;
        }
        try {
            return new DateTime($value);
        } catch (\Exception $e) {
            return;
        }
    }
Validator