我是PHP的新手并尝试比较IF语句中的两个日期。我的问题是IF语句在返回YES时返回NO。
$current_date = date('m-d-Y');
$today = strtotime($current_date);
$first_day_only = new DateTime('first day of this month');
//If today is greater than the first day of the month, then YES else NO
if($today > $first_day_only){
echo "YES";
} else {
echo "NO";
}
答案 0 :(得分:0)
解决方案:
$today = new DateTime();
$first_day_only = new DateTime('first day of this month');
//If today is greater than the first day of the month, then YES else NO
if($today->format('Y-m-d') > $first_day_only->format('Y-m-d')){
echo "YES";
} else {
echo "NO";
}