I am reading a folder with lots of files.
How can I get the creation date of a file. I don't see any direct function to get it.
There are filemtime
and filectime
.
And if the file hasn't been modified, what will happen?
Right-click the file and select Properties. In the Properties window, the Created date, Modified date, and Accessed date is displayed, similar to the example below.
The easiest way to get the file creation date is with the stat command. As we can see, the creation date is shown in the “Birth” field.
Creation Date means the date on which a Purchase Order is submitted by a Participant and accepted by the applicable Fund, including through the Distributor.
The filemtime() function returns the last time the file content was modified.
Use filectime. For Windows it will return the creation time, and for Unix the change time which is the best you can get because on Unix there is no creation time (in most filesystems).
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.
This is the example code taken from the PHP documentation here: https://www.php.net/manual/en/function.filemtime.php
// outputs e.g. somefile.txt was last changed: December 29 2002 22:16:23. $filename = 'somefile.txt'; if (file_exists($filename)) { echo "$filename was last modified: " . date ("F d Y H:i:s.", filemtime($filename)); }
The code specifies the filename, then checks if it exists and then displays the modification time using filemtime()
.
filemtime()
takes 1 parameter which is the path to the file, this can be relative or absolute.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With