首页 > 解决方案 > 如果所需条件大于和小于php中的当前日期,如何检查日期?

问题描述

下面的代码我需要的是!,我得到的输出已经“完成”和“待定”。我应该如何获得“达到极限”有输出。

需要的条件

请帮我解决逻辑。谢谢!

$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);

标签: php

解决方案


@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";
}

推荐阅读