<?php
if(isset($_POST['month']) && isset($_POST['day']) && isset($_POST['year']) && is_int($_POST['month']) && is_int($_POST['day']) && is_int($_POST['year']) && $_POST['month'] > 0 && $_POST['month'] < 13 && $_POST['day'] > 0 && $_POST['day'] < 32 && $_POST['year'] > 0 && $_POST['year'] < 2020){
if(checkdate($_POST['month'],$_POST['day'],$_POST['year'])){
$date = "{$_POST['year']}-{$_POST['month']}-{$_POST['day']}";
}else{
echo "This date does not exist";
}
}else{
echo "Date data not valid";
}
?>
That's just a little clunky - and you could create nicer tests, e.g. stipulating better limits for the year. There are loads of ways to do it. You could use mktime() and date(), or even use the DateTime object.
diafol
Rhod Gilbert Fan (ardav)
7,792 posts since Oct 2006
Reputation Points: 1,170
Solved Threads: 1,080