我要做的是接收到用户输入的年月日,如果用户输入的日期至今天小于18年则为非法
一下是我的判定逻辑:
$month = $_POST['month'];
$day = $_POST['day'];
$year = $_POST['year']; //接受到的日期$nowyear = date("Y");
$nowmonth = date("m");
$nowday = date("d");$Checkyear = $nowyear - 18;//将现在年份减18//一下的if情况全是错误的情况if ( $year > $Checkyear ) {
echo "<script language=javascript>alert('The University cannot accept people who under 18!');window.location.href='addstudent.php';</script>";
exit();
}else if ( $year == $Checkyear && $month < $nowmonth ) {
echo "<script language=javascript>alert('The University cannot accept people who under 18!');window.location.href='addstudent.php';</script>";
exit();
}else if ( $year == $Checkyear && $month == $nowmonth && $day < $nowday) {
echo "<script language=javascript>alert('The University cannot accept people who under 18!');window.location.href='addstudent.php';</script>";
exit();
}$dob = $year.'-'.$month.'-'.$day;
一下是我的判定逻辑:
$month = $_POST['month'];
$day = $_POST['day'];
$year = $_POST['year']; //接受到的日期$nowyear = date("Y");
$nowmonth = date("m");
$nowday = date("d");$Checkyear = $nowyear - 18;//将现在年份减18//一下的if情况全是错误的情况if ( $year > $Checkyear ) {
echo "<script language=javascript>alert('The University cannot accept people who under 18!');window.location.href='addstudent.php';</script>";
exit();
}else if ( $year == $Checkyear && $month < $nowmonth ) {
echo "<script language=javascript>alert('The University cannot accept people who under 18!');window.location.href='addstudent.php';</script>";
exit();
}else if ( $year == $Checkyear && $month == $nowmonth && $day < $nowday) {
echo "<script language=javascript>alert('The University cannot accept people who under 18!');window.location.href='addstudent.php';</script>";
exit();
}$dob = $year.'-'.$month.'-'.$day;
&& $day < $nowday
这两个似乎应该是> ?
月和日是value越大人越大
$date = $year."-"."$month"."-".$day;
if (date("Y-m-d",strtotime($date))>date("Y-m-d",strtotime("-18 years"))){
echo "<script language='javascript'>alert('The University cannot accept people who under 18!');window.location.href='addstudent.php';</script>";
exit();
}
?>