0

How to convert Timestamp into days hours mins ago ?

E.g I have a Timestamp : 2014-02-27 09:37:20

How to convert this timestamp into 4 day, 2 hours ,20mins ago ?

Hassan Sardar
  • 4,413
  • 17
  • 56
  • 92
  • 1
    Please remember to Google first before asking a question. A query for `Convert Timestamp into days hours mins ago` would have given you plenty of existing duplicates. – Pekka Mar 04 '14 at 05:27
  • Try out this video tutorial on it: http://www.developphp.com/view.php?tid=725 – les Mar 04 '14 at 06:23

2 Answers2

0

You should be better of with the DateTime::createFromFormat

<?php
$dt='2014-02-27 09:37:20';
$date = DateTime::createFromFormat('Y-m-d H:i:s', $dt);
$currdt=new DateTime();
$currdt->diff($date);
echo $currdt->format('d')." days ".$currdt->format('H')." hours ".$currdt->format('i')." mins ago";

OUTPUT :

04 days 05 hours 31 mins ago

Demo

Shankar Narayana Damodaran
  • 68,075
  • 43
  • 96
  • 126
0

Is this something you're looking for?

// built with php5

// set system default time zone 
$timeZone = 'UTC';
date_default_timezone_set($timeZone); 

// find the difference
$interval = date_diff(date_create('2014-02-27 09:37:20'), date_create());
$out = $interval->format("Days:%d,Hours:%H,Minutes:%i");
print_r($out);

For the list of available time zone string you may find here http://www.date-default-timezone-set.com/

ydoow
  • 2,969
  • 4
  • 24
  • 40