php – codeigniter中两个日期之间的差异

abscondingsince是一个值为2016-08-24的日期字段,而dateofcontactviaphone是一个值为2016-08-26的日期字段.当我尝试回显时间跨度($row [‘absconding since’],$row [‘dateofcontactviaphone’]);它给出2016-08-2446年,8个月,3天,5小时,43分钟作为输出,而它应该是2天等等.我不知道我犯了什么错误.我的观看代码如下:

<table  cellpadding="10px" border="1" style="background:none;width:75%;" RULES="ROWS" class="tab_data">
  <thead>
    <th>Employee Name</th>
    <th>Absconding Since</th>
    <th>Absconding Days</th>
    <th>Phone Log</th>
    <th>Comments on call made</th>
    <th>Date of Email Sent</th>
    <th>Comments/responses to email recorded</th>
    <th>View Absconding Checklist</th>
  </thead>
  <tbody>
    <?php 
      $serial_no = 1;
      $i = 0;
      foreach($rows as $row){ 
      $i++;


      ?>
    <tr>
      <td style="width:10%">
        <?php echo $row['name']; ?>
      </td>
      </td>
      <td style="width:10%">
        <?php echo $row['abscondingsince'];
          echo timespan($row['abscondingsince'], $row['dateofcontactviaphone']);
           ?>
      </td>
      <td style="width:10%">
        <?php echo $row['dateofcontactviaphone']; ?>
      </td>
      <td style="width:10%">
        <?php echo $row['commentsphone']; ?>
      </td>
      <td style="width:10%">
        <?php echo $row['dateofcontactviaemail']; ?>
      </td>
      <td style="width:10%">
        <?php echo $row['commentsemail']; ?>
      </td>
      <td style="width:10%">
        <?php
          if ($row['last_status'] == 'Accepted'){ 
          echo anchor('exits/view_exit_checklist/'.$row['id'],"<i class='fa fa-eye edit_row' alt='View' title='Edit' rel='".$row['id']."' ></i>",array('rel'=>$row->id,'class'=>'edit_row'));
          }
          else
          {
          echo "NA";
          }
          ?>
      </td>
    </tr>
    <?php               
      } ?>
  </tbody>
</table>

最佳答案 像这样使用: –

echo timespan(strtotime($row['absconding since']), 
               strtotime($row['dateofcontactviaphone']));
点赞