3

i use ths method to find the difference between two timestamp and get the number of seconds between those two times, and i refresh the information with jquery like a counter.

$diff = strtotime(date('Y-m-d H:i:s')) - strtotime('2014-06-25 14:50:03');
$time = intval(date('s', $diff));
echo $time;

When the difference is more than 60 seconds, the $time comes back to 0, like a reset.

i would like to display 1 min XX s for example

John Conde
  • 217,595
  • 99
  • 455
  • 496
DouzeBri DouzeBra
  • 117
  • 1
  • 2
  • 13

3 Answers3

5

The s flag for date() will never return a value greater than 59 as it only represents the current number of seconds of a given time which can never be more than 59 before rolling over into a new minute.

If you want the total number of seconds you can actually remove your second line of code as the difference between two Unix Timestamps is always in seconds:

$time = strtotime(date('Y-m-d H:i:s')) - strtotime('2014-06-25 14:50:03');
echo $time;

If you want to display this as minutes and seconds you can use DateTime() which offers better tools for this:

$now = new DateTime();
$then = new DateTime('2014-06-25 14:50:03');
$diff = $now->diff($then);
echo $diff->format('%i minutes %s seconds');
John Conde
  • 217,595
  • 99
  • 455
  • 496
5

format the date

$diff = strtotime(date('Y-m-d H:i:s')) - strtotime('2014-06-25 14:50:03');
$time = date('i:s', $diff);
echo $time;
javier_domenech
  • 5,995
  • 6
  • 37
  • 59
0

Pass time like 1 & now 2

function diffrencePassTimeAction($DataTime){
    $im = $DataTime - strtotime("now");
  return $im;
}

Future time like 2 & now 1

function diffrenceFuturTimeAction($DataTime){
    $im = strtotime("now") - $DataTime;
  return $im;
}

this function delete (-less)

function diffrencePassTimeAction($DataTime){
    if ($DataTime > 0)
        return $DataTime - strtotime("now");
    else
        return strtotime("now"); // OR return 0;
}
Smar ts
  • 49
  • 5