Php 突出显示从现在到2周后的所有日期
我有一个脚本,其中有一个包含供应日期的表。现在有很多日期+-600。现在我想做的是高亮显示所有从今天到两周后到期的日期,或者如果日期在过去已经准备好了。 这张桌子看起来像这样 现在这些只是几行。但我如何自动突出显示从今天到两周后的所有日期和过去的日期。。。 我已经搜索了很多,我唯一能找到的是在两个日期之间进行高亮显示,但我希望它是自动-->今天-两周后的日期(并且每天自动更新) 对于我的英语,我希望问题是清楚的 提前thx 更新代码:Php 突出显示从现在到2周后的所有日期,php,jquery,css,Php,Jquery,Css,我有一个脚本,其中有一个包含供应日期的表。现在有很多日期+-600。现在我想做的是高亮显示所有从今天到两周后到期的日期,或者如果日期在过去已经准备好了。 这张桌子看起来像这样 现在这些只是几行。但我如何自动突出显示从今天到两周后的所有日期和过去的日期。。。 我已经搜索了很多,我唯一能找到的是在两个日期之间进行高亮显示,但我希望它是自动-->今天-两周后的日期(并且每天自动更新) 对于我的英语,我希望问题是清楚的 提前thx 更新代码: <?php // get two weeks fro
<?php
// get two weeks from now
$date_in_two_weeks = strtotime('+2 weeks');
$date_in_two_weeks = date("Y-m-d",$date_in_two_weeks);
// get the date to compare, from db or whatever you want
$date_to_compare = "2014-02-01";
// compare the date in your list to now + 2 weeks and then put the date difference into $days_difference
$date_from_list = new DateTime($date_to_compare);
$date_in_two_weeks = new DateTime($date_in_two_weeks);
$days_difference = $date_from_list->diff($date_in_two_weeks);
if ($days_difference->days > 14) {
$highlight_css_class = "highlight";
} else {
$highlight_css_class = "none";
}
?>
<style>
.highlight {
color:#cc0000;
}
.none {
}
</style>
<fieldset>
<table class="tablesorter" id="my-table" border="1" style="border-collapse:collapse">
<thead>
<tr>
<th>REK</th>
<th>BESCHRIJVING</th>
<th>VERVALDATUM</th>
</tr>
</thead>
<tbody>
<tr><td>A1</td><td>hamburger</td><td class="<?php echo $highlight_css_class;?>">2014-02-10</td></tr>
<tr><td>A1</td><td>tomato</td><td class="<?php echo $highlight_css_class;?>">2014-06-10</td></tr>
</tbody>
</table>
.突出显示{
颜色:#cc0000;
}
.none{
}
雷克
贝什里金
维瓦尔达姆
a汉堡包假设您使用的是PHP5.3>,您可以使用获取日期与+2周之间的日差,然后决定是否将css类应用于
例如:
// get two weeks from now
$date_in_two_weeks = strtotime('+2 weeks');
$date_in_two_weeks = date("Y/m/d",$date_in_two_weeks);
// get the date to compare, from db or whatever you want
$date_to_compare = "2014/02/01";
// compare the date in your list to now + 2 weeks and then put the date difference into $days_difference
$date_from_list = new DateTime($date_to_compare);
$date_in_two_weeks = new DateTime($date_in_two_weeks);
$days_difference = $date_from_list->diff($date_in_two_weeks);
if ($days_difference->days > 14) {
$highlight_css_class = "highlight";
} else {
$highlight_css_class = "";
}
现在在您的表中,将css类应用于
或任何您想要的地方
<tr>
<td>A1</td>
<td>hamburger</td>
<td class="<?php echo $highlight_css_class;?>">2014-02-10</td>
</tr>
如何显示表格,显示当前表格的一些代码?表格是这样显示的,只是日期是一个变量,如$tomato=“2014-01-09”;您可以通过strotime(“+2周”)提前2周获得收益
以及如何突出显示它们?因为我不知道如何突出显示所有过期日期这是我所需要的。我去看看能不能让它工作。thxit不起作用,所有日期都突出显示,每个类都“突出显示”,当然所有内容都将突出显示,您正在比较相同的日期。。。我想你需要再复习一下基础知识。2014-06-10是表中的第二个日期=它被你的代码染成红色
.highlight {
background:#e1e1e1;
}