我在写if语句时遇到了问题
这里有3个变量
$date = 1985-11-01;
$date2 = 2005-11-08;
$date3 = 2006-11-08;这是我的if语句。
if($date > $date2 && $date < $date3) {
// dob is between the limits
return TRUE;
}
else {
// dob is outside the limits
return FALSE;
}我尝试做的是,如果$date不在$date2和$date3之间,则返回false。我今天很累,我的大脑不工作,谁能告诉我我做错了什么?
发布于 2012-11-09 04:59:29
您可以使用strtotime来确保正确比较。
$date = strtotime('1985-11-01'); //499680000
$date2 = strtotime('2005-11-08'); //1131436800
$date3 = strtotime('2006-11-08'); //1162972800当您执行逻辑时,请查看Unix生成的时间戳...
发布于 2012-11-09 04:58:32
使用strtotime将变量转换为时间对象
$my_date = strtotime('08/11/2012');
发布于 2012-11-09 05:26:06
//using strtotime convert your date(s) in time stamp then your checking will be correctly worked.
$date = strtotime('1985-11-01');
$date2 = strtotime('2005-11-08');
$date3 = strtotime('2006-11-08');
if($date > $date2 && $date < $date3)
return true;
else
return false;https://stackoverflow.com/questions/13297662
复制相似问题