【发布时间】:2016-12-07 16:09:58
【问题描述】:
假设我有一张票 $create_time = "2016-08-02 12:35:04"。我想从当前日期和时间中减去$create_time,例如$current_time="2016-08-02 16:16:02",以找到3hr 41min 格式的年龄。
<?php
$sql = "SELECT count(*) as total, create_time FROM article where ticket_id='$ticket_id'";
$otrs_db = $this->load->database('otrs',true);
$result = $otrs_db->query($sql);
foreach($result->result() as $row)
{?>
<div class="pull-left">
<h4><b><?php echo $row->total ;?> Article(s)</b></h4>
</div>
<div class="pull-right">
<h4>Age: <?php echo date("Y-m-d H:i", strtotime("-$row->create_time",strtotime($thestime))) ?>Created: <?php echo $row->create_time; ?></h4>
</div>
<?php
}
?>
我知道我的日期减法代码是错误的。我怎样才能做到正确?
【问题讨论】:
-
试试
date("Y-m-d H:i", time() - strtotime($row->create_time)) -
我确定这是一个重复的问题,但您应该使用 date_diff()
-
@FrankerZ 你的代码不起作用