W3docs

PHP: how can I get file creation date?

To get the file creation date in PHP, you can use the filectime() function.

To get the file creation date in PHP, you can use the filectime() function. This function returns the time as a Unix timestamp, but its behavior differs by operating system: on Windows it returns the actual creation time, while on Unix/Linux systems it returns the last inode change time (metadata modification).

Here's an example of how to use filectime():

Example of getting the file creation date in PHP

<?php

$filename = '/path/to/file.txt';

if (file_exists($filename)) {
    $file_creation_date = filectime($filename);
    echo "File was created on: " . date('Y-m-d H:i:s', $file_creation_date);
} else {
    echo "File does not exist.";
}

This code will output the timestamp in the format "Y-m-d H:i:s", e.g. "2022-01-01 12:00:00".

Note: On Unix/Linux systems, filectime() tracks metadata changes rather than the original creation date. If you need the last modification time of the file's contents, use filemtime() instead. For reliable creation dates across different operating systems, consider using stat() or platform-specific functions.