Understanding PHP filectime() Function: Syntax, Usage, and Examples

This article explains the PHP filectime() function, its syntax, how it returns a file's creation timestamp, how to format the timestamp with date(), includes practical code examples, and notes the difference from filemtime() and fileatime().

php Courses
php Courses
php Courses
Understanding PHP filectime() Function: Syntax, Usage, and Examples

The filectime() function in PHP retrieves the creation time of a specified file.

Syntax of filectime()

filectime(string $filename): int|false

Here $filename is the path to the file. The function returns an integer timestamp representing the file's creation time, or false on error.

The returned timestamp counts seconds since the Unix epoch (1970‑01‑01 00:00:00 UTC). It can be formatted into a readable date using the date() function.

Example of filectime()

How to use filectime() to obtain a file's creation time:

$filename = 'path/to/file.txt';
$ctime = filectime($filename);
if ($ctime === false) {
    echo "Unable to get file creation time";
} else {
    echo "File creation time: " . date('Y-m-d H:i:s', $ctime);
}

The script first sets the file path, calls filectime(), stores the result in $ctime, checks for false, and if successful formats the timestamp with date().

Notes

filectime()

returns the creation time, not the last modification or access time. For those, use filemtime() and fileatime() respectively.

Summary

The filectime() function obtains a file's creation timestamp, which can be converted to a readable date with date(); it returns false if the creation time cannot be retrieved.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

file-handlingdate functionfilectimefile timestamp
php Courses
Written by

php Courses

php中文网's platform for the latest courses and technical articles, helping PHP learners advance quickly.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.