codeigniter中两个日期之间的差异
Posted
技术标签:
【中文标题】codeigniter中两个日期之间的差异【英文标题】:Difference between two dates in codeigniter 【发布时间】:2016-12-30 09:17:43 【问题描述】:abscondingsince 是一个值为 2016-08-24 的日期字段,而 dateofcontactviaphone 是一个值为 2016-08-26 的日期字段。当我尝试echo timespan($row['absconding since'], $row['dateofcontactviaphone']);
它给出 2016-08-2446 Years, 8 Months, 3 Days, 5 Hours, 43 Minutes 作为输出,而它应该是 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>
【问题讨论】:
【参考方案1】:这样使用:-
echo timespan(strtotime($row['absconding since']),
strtotime($row['dateofcontactviaphone']));
【讨论】:
以上是关于codeigniter中两个日期之间的差异的主要内容,如果未能解决你的问题,请参考以下文章