我要做的是接收到用户输入的年月日,如果用户输入的日期至今天小于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;
解决方案 »
- 关于使用date()和strtotime()打印日期的问题
- 给一个PHP学习的指导。
- 求一个简单数组排序
- 从提交的内容里取出图片上传和取出地址
- 小弟刚学PHP,问下什么样程度才属于高手
- 急!!!php 下载execl文件 格式报错
- PHP变量无法调用
- PHP扩展DLL的问题,急等答案.
- 怎样截取汉字(经过后台编辑器处理的汉字)
- ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffasdfdfdfdfdfd
- 初学PHP,数据集怎么处理成数组
- 麻烦帮看看是哪里错了啊
&& $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();
}
?>