0

I have a time string, the first user's last login : '2014.12.01, 12:25' And how to calculate the time different from now? For e.g. another user see the first user's last login

At 12:30 and it says 5 minute ago.
Or at 13:23 says 48 minute ago.
Or at 14:24 says 1 hour ago.
Or one day later, it says 1 day ago.
Cœur
  • 37,241
  • 25
  • 195
  • 267
  • possible duplicate of [Converting timestamp to time ago in PHP e.g 1 day ago, 2 days ago...](http://stackoverflow.com/a/18602474/67332) – Glavić Dec 01 '14 at 12:55
  • possible duplicate of [Converting timestamp to time ago in PHP e.g 1 day ago, 2 days ago...](http://stackoverflow.com/questions/1416697/converting-timestamp-to-time-ago-in-php-e-g-1-day-ago-2-days-ago) – František Maša Dec 01 '14 at 12:57

2 Answers2

1

You can try the following:

$to_time = strtotime("2014-12-01 12:25:00");
$from_time = strtotime("2014-12-01 12:25:00");

$minutes = round(abs($to_time - $from_time) / 60,2);
$seconds = abs($to_time - $from_time) % 60;

echo "$minutes minute, $seconds seconds";

It had already been answered at the following link:

"Calculate time different in minute and second"

Hope this helps

Community
  • 1
  • 1
Barilee
  • 57
  • 6
0
$first_user_time = '2014-12-01 12:30:00';
$curnt_user_time = '2014-12-01 12:40:00';

$diff = date('h:i:s', strtotime($first_user_time)-strtotime($curnt_user_time))

echo $diff;

//it will give diff in hour : min : seconds
Flexo
  • 87,323
  • 22
  • 191
  • 272