PHP Date Validation
This script uses PHP’s built in checkdate function to verify the date. The values must be split by the month, day, and year values for the function to work.
<?php /** * Date Validation * * This script validates a date to * ensure it is valid according to the * Gregorian calendar. * * @author PHP Simple * @website https://phpsimple.com * @date August 2021 */ // Month Examples $m1 = 3; $m2 = 12; $m3 = 2; // Day Examples $d1 = 31; $d2 = 25; $d3 = 29; // Year Examples $y1 = 1743; $y2 = 2032; $y3 = 2019; /** * The checkdate function looks like this.. * checkdate(month, day, year) */ if (checkdate($m1,$d1,$y1)) { echo "This is a valid date.<br />"; } else { echo "This date is NOT valid.<br />"; } if (checkdate($m2,$d2,$y2)) { echo "This is a valid date.<br />"; } else { echo "This date is NOT valid.<br />"; } if (checkdate($m3,$d3,$y3)) { echo "This is a valid date.<br />"; } else { echo "This date is NOT valid.<br />"; } ?>