0

I am trying to check if pass 5 minutes between two dates.

Here is my code:

    $time = strtotime("+5 minutes").'<br>';
$var = '1518219956';
$e1 = date("d-m-Y H:i",$time);
$e2 = date("d-m-Y H:i",$var);
if($var > $time){
    echo 'true<br>';
    echo 'Time: '.$e1.'<br> Var:'.$e2;
} else{
    echo 'false<br>';
    echo 'Time: '.$e1.'<br> Var: '.$e2;
}

I am sorry but I lost myself with this timestamps..

Dani Prime
  • 59
  • 7
  • 1
    Duplicate of https://stackoverflow.com/questions/365191/how-to-get-time-difference-in-minutes-in-php or https://stackoverflow.com/questions/676824/how-to-calculate-the-difference-between-two-dates-using-php?rq=1 or https://stackoverflow.com/questions/1770564/getting-the-difference-between-two-time-dates-using-php?rq=1 or https://stackoverflow.com/questions/15063595/calculate-passed-time-with-php?rq=1 – Brian Gottier Feb 10 '18 at 00:43

1 Answers1

3

Sorry, I don't mean to be rude but I was confused by the question. What I designed here was to see if time B is five minutes after Time A.

A few notes: No need to bother with strtotime or date. Just keep everything in unix time. Compare the seconds by using 60 * 5. 60 for 60 seconds in a minute and 5 for the number of minutes.

<?php
//Time A 
$timeA = '1518223062';

//Time B (Which I set at the current time)
$timeB = time();

//five minutes in seconds
$fiveMinutes = 60 * 5;

//check if current time is after 5 minutes the initial time
if ( ($timeA+$fiveMinutes) <= $timeB) {
  echo "True";
}
else {
  echo "False";
}


?>
Mike
  • 331
  • 2
  • 12