What is the filemtime() function in PHP?

The filemtime() function is a built-in function in PHP. It returns the time when any specified file contents were last modified by the user.

Syntax

filemtime($filename)

$filename: The file we want to check to determine when it was last modified.

Return value

This method returns a Unix timestamp denoting the last modified time. It returns False if the function does not execute successfully.

Code

Let’s look at the code, which determines when the contents of hello.txt were last modified:

main.php
hello.txt
<?php
// Checking last modified time of file
echo filemtime("hello.txt");
echo "\n";
// formatting the data in data and time format
echo "Checking last modified time of file: ".date("F d Y H:i:s.",
filemtime("hello.txt"));
?>

Free Resources

Copyright ©2025 Educative, Inc. All rights reserved