I tried to compare the difference between the two dates, but it seems that the results are pretty wrong, for example, this code:
$datetime1 = new DateTime('2009-10-11'); $datetime2 = new DateTime('2009-10-13'); $interval = $datetime1->diff($datetime2); echo $interval->format('%R%a days')."<br />"; $datetime1 = new DateTime('2009-10-11'); $datetime2 = new DateTime('2009-10-15'); $interval2 = $datetime1->diff($datetime2); echo $interval2->format('%R%a days')."<br />"; if($interval == $interval2){ echo "true"; }else{echo "false"; }
Returns true, but above you can see that the differences in the date do not match, in fact, the echo print is +2 and +4. Any idea comparing the two date differences?
EDIT: datetime :: diff returns a dateinterval object, in fact it does not implement comparison operators, https://bugs.php.net/bug.php?id=49914 I will use timinterval vars to check the difference, thanks for the answers
source share