0

Well i have a time in UNIX format. i need to find the difference between a specific time and current time. if difference is 5 minutes. do something.

$sp_time = 1400325952;//Specific time
$currentTime = //current time in UNIX format

$difference = $currentTime - $sp_time;
if($difference >= 5)//if difference is less than or equal to 5minutes
{
    //DO SOME STUFF
}

EDIT : How to find the difference in minutes and how to get currenttime?

Matarishvan
  • 2,382
  • 3
  • 38
  • 68

2 Answers2

2

Try to get minute first using date() then compare like

$sp_time = 1400325952;//Specific time
$currentTime = time(); // current time 
$difference = $currentTime - $sp_time;
if(date('i',$difference) >= '5') {
    //DO SOME STUFF
}
Rakesh Sharma
  • 13,680
  • 5
  • 37
  • 44
1

Not sure if this is what you are looking for...

$sp_time = 1400325952;//Specific time
$currentTime = time(); // current time 
$diff = abs($currentTime - $sp_time);

$mins = round($diff / 60);

if ($mins <= 5) {
echo "difference is less than or equal to 5minutes: $mins";
}
rubberchicken
  • 1,270
  • 2
  • 21
  • 47