请考虑以下代码:
$today = date("d/m/Y");
$start_date = '20/11/2014';
$time1 = strtotime($start_date1);
$start_date1 = date('d/m/Y',$time1);
$end_date = '20/01/2015';
$time2 = strtotime($end_date1);
$end_date1 = date('d/m/Y',$time2);
if( $start_date1 <= $today && $end_date1 >= $today)
echo "yes";
else
echo 'no';
即使$今天是在开始日期和结束日期之间,我也得到了#34; no&#34;作为回报。这可能是什么问题?我只想检查今天是否在这些日期之间。开始日期和结束日期在DB中保存为字符串。
答案 0 :(得分:5)
试试这个:
<?php
$now = new DateTime();
$startdate = new DateTime("2014-11-20");
$enddate = new DateTime("2015-01-20");
if($startdate <= $now && $now <= $enddate) {
echo "Yes";
}else{
echo "No";
}
?>