How to check the given input is valid date format in PHP

Code Example:

$startDate = $_REQUEST['start_date']; //get input date

if (!empty($startDate)) {
	if (preg_match("/^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])$/", $startDate)) {
		echo "Valid date format";
	} else {
		echo "Date format should be YYYY-MM-DD";
	}
}

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *