PHP 检查今天是否在两个日期之间
PHP check if today is in between two dates
考虑以下代码:
$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';
即使 $today 在开始日期和结束日期之间,我在 return 中得到 "no"。这可能是什么问题?我只想检查今天是否在这些日期之间。开始日期和结束日期在数据库中保存为字符串。
试试这个:
<?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";
}
?>
考虑以下代码:
$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';
即使 $today 在开始日期和结束日期之间,我在 return 中得到 "no"。这可能是什么问题?我只想检查今天是否在这些日期之间。开始日期和结束日期在数据库中保存为字符串。
试试这个:
<?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";
}
?>