Я немного покопался в Интернете и Stackoverflow ( PHP Как найти время, прошедшее с даты? ), и вот мое решение:
Это полный ответ, дающий удобочитаемое представление о возрасте файла + проверка, чтобы увидеть, если файлу 2 часа или нет.
<?php
function humanTiming ($time)
{
// to get the time since that moment
$time = time() - $time;
// time unit constants
$timeUnits = array (
31536000 => 'year',
2592000 => 'month',
604800 => 'week',
86400 => 'day',
3600 => 'hour',
60 => 'minute',
1 => 'second'
);
// iterate over time contants to build a human
$humanTiming;
foreach ($timeUnits as $unit => $text)
{
if ($time < $unit)
continue;
$numberOfUnits = floor($time / $unit);
// human readable token for current time unit
$humanTiming = $humanTiming.' '.$numberOfUnits.' '.$text.(($numberOfUnits>1)?'s':'');
// compute remaining time for next loop iteration
$time -= $unit*$numberOfUnits;
}
return $humanTiming;
}
$filename = '/path/to/your/file.extension';
if (file_exists($filename))
{
echo 'Now = '.date ("Y-m-d H:i:s.", time());
echo "<br/>$filename was last modified on " . date ("Y-m-d H:i:s.", filemtime($filename));
$time = strtotime('2010-04-28 17:25:43');
$time = filemtime($filename);
echo '<br/>File age is '.humanTiming($time).'.';
$fileAge = time()-filemtime($filename);
echo '<br/>Is file older than 2 hours? '.(($fileAge < (2*3600))?'No':'Yes').'.';
}
?>
Вот вывод на моей стороне:
Now = 2013-01-29 09:10:12.
/path/to/your/file.extension was last modified on 2013-01-29 08:07:52.
File age is 1 hour 2 minutes 20 seconds.
Is file older than 2 hours? No.