3v4l.org

run code in 300+ PHP versions simultaneously
<?php class DateTimeType { private const FORMAT = 'Y-m-d H:i:s'; private const TIMEZONE = 'Europe/Berlin'; public static function isValidDateTimeOld(string $value): bool { $date = DateTime::createFromFormat(self::FORMAT, $value, new DateTimeZone(self::TIMEZONE)); $errors = DateTime::getLastErrors(); return $date && $errors['warning_count'] === 0 && $errors['error_count'] === 0; } public static function isValidDateTimeNew(string $value): bool { $date = DateTime::createFromFormat(self::FORMAT, $value, new DateTimeZone(self::TIMEZONE)); $errors = DateTime::getLastErrors(); return $date && !$errors; } } $dateTimeToCheck = '2022-02-17 13:37:00'; var_dump(DateTimeType::isValidDateTimeOld($dateTimeToCheck)); var_dump(DateTimeType::isValidDateTimeNew($dateTimeToCheck));

preferences:
107.45 ms | 404 KiB | 5 Q