php - how to calculate time left using string minus another string? -


i have lets $value = 5; , valnue means 5 minutes, , have file saved on server , getting modified lot called check.txt want code calculation of if timenow - timemodification of file <= 0 in h:i:s main $value of 5 minutes continue, else echo please wait minutes left time - filetimemodification of main value of 5 minutes = $timeleft in m:s format.

i'm testing on current code keep getting value of -1376352747

my code know bad :)

$filename = 'check.txt'; $time = date("h:i:s"); $time = str_replace("00", "24", $time); $filemodtime = filemtime($filename); $timeleft = $time - $filemodtime; $h = explode(':', $time); $h = $h[0]; $h = str_replace("00", "24", $h); $m = explode(':', $time); $m = $m[1]; $s = explode(':', $time); $s = $s[2]; $hms = ("$h:$m:$s");  if (count($filemodtime - $time) <= 0) {  echo "you can continue"; }  else {  echo " please wait $timeleft"; } 

thanks in advance

the filemtime() function returns unix-timestamp in seconds, , time() function returns current time unix-timestamp. using difference, file's age in seconds.

$age = time() - filemtime($filename);  // if older 5 minutes (5 * 60 secounds) if($age > $value*60) {     // } else {    $time_left = $value * 60 - $age;    $time_left_secounds = $time_left % 60;    $time_left_minutes = ($time_left - $time_left_secounds) / 60;    $formated_time_left = sprintf("%02d:%02d", $time_left_minutes, $time_left_secounds);     echo "please wait {$formated_time_left}"; } 

Comments

Popular posts from this blog

ios - UICollectionView Self Sizing Cells with Auto Layout -

node.js - ldapjs - write after end error -

DOM Manipulation in Wordpress (and elsewhere) using php -