I have 2 variables,
$current_date = "27-05-2017";
$due_date = "29-05-2017";
All the above date is dynamic which is fetched from mysql. $due_date
will change.
If the $due_date
is within +3 days from the $due_date
, then the color should change.
For example,
If $current_date = "27-05-2017"
and $due_date = "28-05-2017", $due_date = "29-05-2017", $due_date = "30-05-2017"
the color should be orange
.
If $current_date = "27-05-2017"
and $due_date = "31-05-2017", $due_date = "01-06-2017"
the color should be blue
.
I have tried using the below code.
$due_date = "30-05-2017";
$cur_date = "27-05-2017";
if($due_date > strtotime("+1 day", strtotime($cur_date)) or $due_date < strtotime("+2 day", strtotime($cur_date)) or $due_date < strtotime("+3 day", strtotime($cur_date)))
echo "orange";
else
echo "blue";
The code not working for all the conditions. How to fix this.
You can do with one condition:
$due_date = "30-05-2017";
$cur_date = "27-05-2017";
if(strtotime($due_date) > strtotime($cur_date) && strtotime($due_date) <= strtotime("$cur_date +3 day"))
echo "orange";
else
echo "blue";
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.