Reputation: 824
Hey i would like to know if there is any script (php) that could check if a specified date three days before today.
say..
$d1 = date("Y-m-d", filemtime($testfile));
$d2 = date("Y-m-d");
now i would like to know how to compare this two dates to check if d1 is atleast 3days ago or before d2 any help would be gladly appreciated.
Upvotes: 5
Views: 9503
Reputation: 373
well, stunned to see no one is using mktime() function, it makes the job simple
for example your input date is :10/10/2012
mktime convert it to unix time stamp
$check_date=mktime(0,0,0,10,**10+3**,2012);
we can perform any operations weather +,-,*,/
Upvotes: 1
Reputation: 2822
Why not to use DateTime object.
$d1 = new DateTime(date('Y-m-d',filemtime($testfile));
$d2 = new DateTime(date('Y-m-d'));
$interval = $d1->diff($d2);
$diff = $interval->format('%a');
if($diff>3){
}
else {
}
Upvotes: 8
Reputation: 1088
use date("Y-m-d", strtotime("-3 day"));
for specific date
you can also use
strtotime(date("Y-m-d", strtotime("-3 day")));
to convert it to integer before comparing a date string
Upvotes: 1
Reputation: 160833
Just check it with timestamp:
if (time() - filemtime($testfile) >= 3 * 86400) {
// ...
}
Upvotes: 3
Reputation: 6736
use timestamp instead of date,
$d1 = filemtime($testfile);
$now = time();
if ($now - $d1 > 3600*24*3) {
..
}
Upvotes: 0
Reputation: 173562
Assuming you wish to test whether the file was modified more than three days ago:
if (filemtime($testfile) < strtotime('-3 days')) {
// file modification time is more than three days ago
}
Upvotes: 4