I'm getting thoroughly confused about the various date functions and formats in php so I would like to ask for help if possible.
I'm trying to find files that were modified between two dates but the syntax is confusing me. For instance, if I tried to find files altered between 6 months and 1 year ago, I have tried:
$yearago = new DateTime("now");
date_sub($yearago, date_interval_create_from_date_string("1 year"));
$sixmonthsago = new DateTime("now");
date_sub($sixmonthsago, date_interval_create_from_date_string("6 months"));
$dir = '/datacore/';
$files1 = scandir($dir);
foreach($files1 as $key => $value)
{
$datemod = filemtime($value);
if ($datemod>$yearago && $datemod<$sixmonthsago) // eg between 6 and 12 months ago
{
// Do stuff
}
}
I know this is inefficient; finding an array of filenames in the directory and then looping through this array on filemtime but this is something to work on in the future, but its the mix of date and DateTime thats got me confused.