php - 如何在php中比较天数和当前天数?
问题描述
<table class="table row-border order-column">
<thead>
<tr>
<th></th>
<?php
$days = cal_days_in_month(CAL_GREGORIAN, $month, $year);
for($i=1;$i<=$days;$i++)
{
?>
<th><?php echo $i; ?></th>
<?php
}
?>
</tr>
</thead>
<tbody>
<?php
foreach ($student as $key => $value)
{
?>
<tr>
<td class="cap"><?php echo $value->name; ?></td>
<?php
for($i=1;$i<=$days;$i++)
{
$result = $this->db->select('*')->from('attendance')->where('studentID',$value->studentID)->where('day(date)', date($i))->where('month(date)', date($month))->where('Year(date)', date($year))->get()->row();
if(empty($result))
{
$date = date('Y-m-d');
$current_date = date('d',strtotime($date));
if($i < $current_date)
{
?>
<td class="absent">A</td>
<?php
}
else
{
?>
<td></td>
<?php
}
}
else
{
$dateday = date('d',strtotime($result->date));
if($i == $dateday)
{
?>
<td class="present">P</td>
<?php
}
}
}
?>
</tr>
<?php
}
?>
</tbody>
在上面的代码中,我想在比较时显示缺席$current_date
,$days
但现在这里发生的情况只有当前月份日期显示缺席,上个月日期显示空白。现在,我要做什么我不想absent
在未来的日期显示。那么,我该怎么做呢?请帮我。
谢谢你
解决方案
使用 Unix 时间戳进行计算,然后使用准备好的函数将 Unix 更改为 gmt 或 utc 时间。
推荐阅读
- python - Tkinter 复选框问题
- gcc - LD:使用 ALIGN() 的不同方式
- android - 适用于 Android 和 iOS 的 Facebook 应用内浏览器深度链接问题
- javascript - 在 JS 脚本中为 font-awesome 添加颜色
- python - 在 django 中导入类的正确方法是什么?
- python - django rest 框架:如何使用相关字段验证序列化程序中的规则
- pdf - 如何使用 itextstarp 在 pdf 中添加 html 复选框、单选按钮、文本框?
- unity3d - 如何在网格中对齐平铺游戏对象
- gradle - 提供者 org.jetbrains.plugins.gradle.tooling.builder.WarModelBuilderImpl 无法实例化
- visual-studio - 你调用的对象是空的; 我试着修复它