PHP date time greater than today

前端 未结 1 1645
夕颜
夕颜 2020-12-08 02:11

please help what\'s wrong with my code? It always returns that today\'s date is greater than \'01/02/2016\' wherein 2016 is greater than in 2015.



        
1条回答
  •  粉色の甜心
    2020-12-08 02:44

    You are not comparing dates. You are comparing strings. In the world of string comparisons, 09/17/2015 > 01/02/2016 because 09 > 01. You need to either put your date in a comparable string format or compare DateTime objects which are comparable.

     '2016-01-02') {
        echo 'greater than';
    }else{
        echo 'Less than';
    }
    

    Demo

    Or

     $date2) {
        echo 'greater than';
    }else{
        echo 'Less than';
    }
    

    Demo

    0 讨论(0)
提交回复
热议问题