Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP: how can I get file creation date?

Tags:

file

php

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?

like image 213
zod Avatar asked Dec 09 '10 17:12

zod


People also ask

How can you find the creation date of a file?

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.

How can you find the creation date of a file Linux?

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.

What is a create date?

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.

Which command gives information about time of last modification done on file PHP?

The filemtime() function returns the last time the file content was modified.


2 Answers

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.

like image 138
Alin Purcaru Avatar answered Sep 22 '22 14:09

Alin Purcaru


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.

like image 45
Rakesh Dongarwar Avatar answered Sep 23 '22 14:09

Rakesh Dongarwar