[英]change color if due date within 3 days from current date php
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. 以上所有日期都是动态的,是从mysql获取的。
$due_date
will change. $due_date
将更改。
If the $due_date
is within +3 days from the $due_date
, then the color should change. 如果
$due_date
是内从3天$due_date
,那么颜色应该改变。
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
. 如果
$current_date = "27-05-2017"
和$due_date = "28-05-2017", $due_date = "29-05-2017", $due_date = "30-05-2017"
则颜色应为orange
。
If $current_date = "27-05-2017"
and $due_date = "31-05-2017", $due_date = "01-06-2017"
the color should be blue
. 如果
$current_date = "27-05-2017"
和$due_date = "31-05-2017", $due_date = "01-06-2017"
则颜色应为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";
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.