Given the $interval is a DateInterval object following conditional statement is true whether the anniversary is within 1 year prior to the current date = 0 or the anniversary is within 1 year post the current date = -0.
$interval = $anniversary->diff($current_Date);
if ($interval->format('%r%y') < 0){
do something
}
So I want to be able to say something like is this number signed negative but no such thing exists as far as I can tell. Any thoughts?
** Edit **
The solution is to compare the date objects and decide if they are in the appropriate DateInterval:
if ($anniversary < $current_Date && $interval->format('%r%y') == 0){
As the returned value of DateTime::diff() is a DateInterval object, the solution is to use the DateInterval::invert property:-
$interval = $anniversary->diff($current_Date);
if ($interval->invert){
//do something
}
To quote the manual:-
invert
Is 1 if the interval represents a negative time period and 0 otherwise. See DateInterval::format().
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With