PHP - Get files modified on a particular date

Author - Kiran Preet

Solution: In following example we have filtered files which are modified on current date (today’s date):

$source= "C:\wamp\www\Files\";
$files = scandir($source);
$archiveFiles = array();
foreach($files as $file)
if (!in_array($file,array(".","..")))
$lastModified = date('d/m/y',filemtime($source . '/' .$file));
array_push($archiveFiles, $file);

$source contains the path of folder that contains files.

date(‘d/m/y’,filemtime($source . ‘/’ .$file)); Get modified date of files. We can change the format of date too for e.g. date(‘d-m-y’,filemtime($source . ‘/’ .$file));. You can also get timestamp value. Using timestamp you can filter the files according to time also.

IF($lastModified==date(“d/m/y”)) This will compare the last modified date with today’s date.

$archiveFiles array contains the filtered file names.

Webner Solutions is a Software Development company focused on developing Insurance Agency Management Systems, Learning Management Systems and Salesforce apps. Contact us at for your Insurance, eLearning and Salesforce applications.

Leave a Reply

Your email address will not be published.