我从Stackoverflow那里获得了这段代码,并对其进行了少许更改以适应今天的日期。
我想检查今天是否适合两个日期之间。但这是行不通的。我想念什么?
$paymentDate = date('d/m/Y'); echo $paymentDate; // echos today! $contractDateBegin = date('d/m/Y', '01/01/2001'); $contractDateEnd = date('d/m/Y', '01/01/2015'); if ($paymentDate > $contractDateBegin && $paymentDate < $contractDateEnd) { echo "is between"; } else { echo "NO GO!"; }
编辑: 使用<=或> =来计算今天的日期
这是您的代码的正确答案。只需使用strtotime()php函数
$paymentDate = date('Y-m-d'); $paymentDate=date('Y-m-d', strtotime($paymentDate)); //echo $paymentDate; // echos today! $contractDateBegin = date('Y-m-d', strtotime("01/01/2001")); $contractDateEnd = date('Y-m-d', strtotime("01/01/2012")); if (($paymentDate >= $contractDateBegin) && ($paymentDate <= $contractDateEnd)){ echo "is between"; }else{ echo "NO GO!"; }