How core to compare the dates in this way?
$ today = date ('y-M-d');
$ outdate = "2011-11-02";
If ($ Today & GT; = $ Outdate) {...
I used to know it was necessary to translate into different TimesTamps, but it seems now, if you specify a date in such a format. everything should be ok, isn’t it?
Answer 1, Authority 100%
If both dates are exactly in Y-M-D
(or Y-M-D H: I: S
), then logically compare them as strings, i.e.
$ date1 = '2011-02-12';
$ DATE2 = '2012-02-13';
$ result = ($ DATE1 & LT; $ DATE2); // $ Result === True
But if there is no confidence that the date format is the same, then it is better to bring them to unixtime format and compare as numbers:
$ date1 = '2011-02-12';
$ DATE2 = '13 .02.2012 ';
$ result = ($ DATE1 & LT; $ DATE2); // $ Result === False
$ result = (StrTotime ($ DATE1) & lt; Strtotime ($ DATE2)); // $ Result === True
Answer 2, Authority 25%
Use the strtotime , i.e. Move your lines that you get through Date in the Unix Time Label, i.e. In the number of int and then it is convenient to compare
Answer 3, Authority 8%
Compare as the dates lines can not be in no case, it will not be correct if you have:
$ date1 = '01. 03.1956 ';
$ DATE2 = '05 .06.1930 ';
Expression $ DATE2 & GT; $ DATE1? True: false;
return the true
for the reason that the lines are compared in prevail, respectively, since 5 & gt; 1, line $ DATE2 & GT; $ DATE1
.
Of course, the Format 2011-02-12
will return the correct comparison, but this is a potentially dangerous code.