3v4l.org

run code in 300+ PHP versions simultaneously
<?php $input = '1990-09-15'; // $input = '15-09-1990'; // $input = '1990-49-85'; $a = DateTime::createFromFormat('Y-m-d', $input); if ($a === false) { echo "Invalid format\n"; } $lastError = DateTime::getLastErrors()['warnings'] ?? []; if (reset($lastError) === 'The parsed date was invalid') { echo "Invalid date\n"; }
Output for 8.1.34, 8.2.28 - 8.2.30, 8.3.5 - 8.3.30, 8.4.5 - 8.4.18, 8.5.0 - 8.5.3

preferences:
57.01 ms | 630 KiB | 4 Q