0

Im trying to get the difference between to timestamps in PHP.

For instance I have a login time

  $login = "2014-11-24 13:45:00";
  $current_time = date('Y-m-d H:i:s');  // Lets pretend its 2014-11-24 14:50:00

I want to compare the login time with the current time, and show it in two formats

The obvious display I already have is this. Showing the difference.

  01:05:00 // Time difference

But I also want to have this be in a decimal format for calculations. How can I convert the above 'difference' to a decimal display.??

  1.083  // In this case 1:05 difference calculates to 1.083 in decimal 

More examples...

 00:30:00 // half hour difference
 0.5 // Decimal

 00:45:00 // 45 minutes
 0.75 // Decimal

 03:14:00 // 3 hours 14 minutes
 3.23 // Decimal
Kylie
  • 11,421
  • 11
  • 47
  • 78

1 Answers1

3
  $login = strtotime("2014-11-27 01:00:00");
  $current_time = time();
  echo "Difference in Hours: ". ($current_time-$login)/3600;

Simple :)

Fiddle

Hanky Panky
  • 46,730
  • 8
  • 72
  • 95