php - 如果语句返回 NO,则应返回 YES
问题描述
我是 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";
}
解决方案
解决方案:
$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";
}
推荐阅读
- laravel - laravel 与 vue 生成图组件
- c# - 接口对象 IDbconnection
- javascript - Reactjs 功能组件中的 Jest SpyOn
- javascript - 加载单页应用程序的 Javascript 'while' 循环不起作用
- c# - 等效于 python 代码映射和 lambda 的 C#
- python - 加载数据集以训练模型
- grails-4 - Grails4 webapp 不再启动
- amazon-web-services - 您如何在 dotnet core lambda 中接收来自 AWS 事件桥的事件?
- shell - FFMPEG: add more tracks to previous amix output
- jquery - 需要在jquery动画中隐藏溢出