PHP get create time of directory

No. Not reliably.

That's because ctime is not about creation, but change, as pointed out in Gordon's comment. So while filectime() does work on directories (at least on a Unix machine), chances are it will not give you the date you are looking for. See the notes on the PHP Doc page for filectime():

Note also that in some Unix texts the ctime of a file is referred to as being the creation time of the file. This is wrong. There is no creation time for Unix files in most Unix filesystems.

In other words, creating a new file in a directory will likely change the ctime of the directory. If you really need to keep track of the creation time, you need to implement the housekeeping yourself.


It should work for directories, this is what I get:

$ php -r "echo filectime(__DIR__);"
1311596297

You can use the PHP stat function:

Gathers the statistics of the file named by filename. If filename is a symbolic link, statistics are from the file itself, not the symlink.

Sample:

<?php
    $stat = stat('/your/path');
    echo $stat['ctime'];
?>

It returns the create time as Unix timestamp.


In unix a folder is also a file. So it should work for that too

$folder = 'includes';

echo date ("F d Y H:i:s.", filemtime($folder));

Output is

October 06 2010 20:20:58.

Tags:

Php