280 of 410 menu

The filectime Function

The filectime function returns the file creation time as a Unix timestamp - the number of seconds since 1 January 1970. The function takes the file path as a parameter. If the file does not exist, the function will return false.

Syntax

filectime(filename);

Example

Get the creation time of the current file and output it in a human-readable format:

<?php $filename = __FILE__; $timestamp = filectime($filename); echo "File created: " . date("Y-m-d H:i:s", $timestamp); ?>

Code execution result:

'File created: 2023-05-15 14:30:22'

Example

Check if the file exists before getting its creation time:

<?php $filename = 'test.txt'; if (file_exists($filename)) { echo "File created: " . date("Y-m-d H:i:s", filectime($filename)); } else { echo "File not found"; } ?>

Code execution result (if the file does not exist):

'File not found'

See Also

  • the filemtime function,
    which returns the modification time
  • the fileatime function,
    which returns the access time
  • the clearstatcache function,
    which clears the file status cache
byenru