-6

A file updates every 60 minutes. I would like to have a countdown for the next update from comparing filemtime with time.

I'm getting a brain fart dealing with time

hitmanex
  • 1
  • 1
  • 2

1 Answers1

4

Both filemtime() and time() return an Unix Timestamp: the number of seconds since January 1 1970 00:00:00 GMT. So, just subtract the value of filemtime() to the value of time() and you get the number of seconds elapsed since the file was last modified.

$modifiedTime = filemtime("somefile.txt");
$now = time();
$timeSinceModified = $now - $modifiedTime; //Time since modified in seconds.

If you want the value in another unit of time just multiply or divide it.

For instance, $timeSinceModified / 60 will give you the time in minutes.

Telmo Marques
  • 5,066
  • 1
  • 24
  • 34