pTutorial

New way to learn PHP function

PHP filemtime Function

Syntax

filemtime($string);
Parameter Description
Filename $string (file name )

Definition

It Returns the time the file/path $string was last written, or FALSE upon failure. Returned value is a Unix timestamp.

Usage

filemtime function is used to find the last written time of file.

Example of rename function

<?php

$time = filemtime('example-abs1.php');

echo date('m-d-Y g:i:sa', $time);

?>

In above example $time is available that store the Unix timestamp so that date function is used to convert the Unix timestamp to readable time.

.

Note: The results are cached. So clear the cache of browser for accurate result.

Example

<?php

$time = @filemtime('example-abs1.php');
if($time)
{
echo date('m-d-Y g:i:sa', $time);
}
else
{
echo " File is not there. ";
}
?>

Output

File is not there.

If file does not exist, it returns warning message like that Warning: filemtime(): stat failed for example-abs1.php, so that we are using at (@) in from of filemtime function to suppress/ignore the warning message.

fileatime()

Similar as filetime function, it returns the last time the file was accessed.

Example

<?php

$time = fileatime('php-min-function.php');
if($time)
{
echo date('m-d-Y g:i:sa', $time);
}
else
{
echo " File is not there. ";
}

?>

Output

08-18-2017 1:51:23pm

QUOTES OF THE DAY

Knowledge itself is a power.

LIKE ON FACEBOOK

+1 ON GOOGLE

SHARE ON TWITTER