Reputation:
I have the following PHP code
$febdate = date('Y-02-01', time());
$maydate = date('Y-05-01', time());
$augdate = date('Y-08-01', time());
$novdate = date('Y-11-01', time());
$today = date('Y-m-d', time());
$paymentDate = 'Error';
if(($today > $novdate) && ($today < $febdate)){
$paymentDate = $febdate;
}
if(($today > $febdate) && ($today < $maydate)) {
$paymentDate = $maydate;
}
if(($today > $maydate) && ($today < $augdate)) {
$paymentDate = $augdate;
}
if(($today > $augdate) && ($today < $novdate)) {
$paymentDate = $novdate;
}
echo $paymentDate;
What I want to do is set the Payment Date to one of the dates in the $dates
array. So I take todays date, and check if that is in between two dates, if it is I explicitly want to set $paymentDate
to one of the dates in the array based on which two dates it is inbetween. The problem here is that I am not hitting any of my if statements. I am unsure if I have formatted the dates correctly or if they are being passed as strings into the if statements.
Also I am unsure if there is an easier way of doing this to find the next payment date.
Upvotes: 0
Views: 54
Reputation: 29462
First of all, every date in your array has same year. In first condition yo are checking if today is later than November 2016 (true) and before February 2016 (false), so it is impossible condition.
Secondly, you should also check for equal dates, since if it was first day of given month, none of your conditions would match.
(Hint you can introduce new variable with next year and check it in the end. Also drop comparing to $novdate
in first condition)
Upvotes: 1