3v4l.org

run code in 500+ 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.32, 8.3.5 - 8.3.33, 8.4.5 - 8.4.24, 8.5.0 - 8.5.9

preferences:
50.18 ms | 685 KiB | 4 Q