简体   繁体   English

codeigniter中两个日期之间的差异

[英]Difference between two dates in codeigniter

abscondingsince is a date field with value 2016-08-24 and dateofcontactviaphone is a date field with value 2016-08-26 . abscondingsince是一个值为2016-08-24的日期字段,而dateofcontactviaphone是一个值为2016-08-26的日期字段。 when I try to echo timespan($row['absconding since'], $row['dateofcontactviaphone']); 当我尝试echo timespan($row['absconding since'], $row['dateofcontactviaphone']); its giving 2016-08-2446 Years, 8 Months, 3 Days, 5 Hours, 43 Minutes as the output whereas it should have been 2 days and so on. 它给出2016-08-2446年,8个月,3天,5小时,43分钟作为输出,而它应该是2天等等。 I have no clue where I am making a mistake. 我不知道我犯了什么错误。 My view code is as below: 我的观看代码如下:

<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>

Use like this:- 像这样使用: -

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM