php - 如果所需条件大于和小于php中的当前日期,如何检查日期?
问题描述
下面的代码我需要的是!,我得到的输出已经“完成”和“待定”。我应该如何获得“达到极限”有输出。
需要的条件
如果
$current
日期大于$next_due_on_date
它应该显示输出有“待定”。在这种情况下,我需要像“30 天到期”这样的通知,即在
$next_due_on_date
达到其限制之前。如果
$current
日期小于$next_due_on_date
它应该显示输出已“完成”。
请帮我解决逻辑。谢谢!
$current_date = date('Y-m-d G:i:s'); //Current date
$next_due_on_date = '24/10/2018'; //$next_due_on
$next_due_on_date = str_replace('/', '-', $next_due_on_date); //Replacing the format with str_replace
$highlight_date = date("Y-m-d", strtotime("$next_due_on_date 0 years 0 months -30 days")); //$highlight_date is to subtract the next_due_on_date with -30 days
if($current_date <= $highlight_date){
$output = "Completed";
}elseif($current_date > $highlight_date){
$output = "Pending";
}else{
$output = "Reached the limit"
}
print_r($output);
解决方案
@Arun
我没有正确理解您的要求,但据我所知,您可以这样尝试。
<?php
function s2t($value){
return strtotime($value);
}
$date1 =
$date2 = date('Y-m-d',strtotime('+30days'));
$date3 = date('Y-m-d',strtotime('-30days'));
if( s2t($date1) > s2t($date2) ){
echo "30+ Days left";
}else{
echo "30 Days Left";
}
推荐阅读
- c++ - 带有“enum”模板专业化问题的“enable_if”
- java - 像 REPL 控制台一样执行/评估代码的 Java 库
- java - 如何将数组作为参数传递给 Java 图形函数?
- jquery - jQuery 对话框未在加载回调中打开
- android - 当孩子身高增加时,ScrollView 不滚动
- python - 尝试安装 TensorFlow-GPU...失败并出现 ImportError:DLL 加载失败:找不到指定的模块
- ionic-framework - 如何在 IONIC 中下载特定版本的插件?
- kubernetes - 如何在 Helm 中模板化文件对象
- c# - 实时读取和处理数据
- jquery - 如何使用jQuery选择的类来定位表的第二列