티켓이 있다고 가정합니다 $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
}
?>
날짜 빼기 코드가 잘못되었음을 알고 있습니다. 어떻게 바로 할 수 있습니까?
DateTime
클래스 를 사용해야 합니다.
$create_time = "2016-08-02 12:35:04";
$current_time="2016-08-02 16:16:02";
$dtCurrent = DateTime::createFromFormat('Y-m-d H:i:s', $current_time);
$dtCreate = DateTime::createFromFormat('Y-m-d H:i:s', $create_time);
$diff = $dtCurrent->diff($dtCreate);
echo $diff->format("%Y-%m-%d %H:%i");
자세한 형식 지정 세부 정보를 보려면 00-0-0 03:40
See DateInterval::format
를 반환합니다 .
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다