首页 > 解决方案 > 如何在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在未来的日期显示。那么,我该怎么做呢?请帮我。

谢谢你

标签: phpcodeigniter

解决方案


使用 Unix 时间戳进行计算,然后使用准备好的函数将 Unix 更改为 gmt 或 utc 时间。


推荐阅读