Reputation: 123
At the moment I have a query which check the date from an external website and give me some information if that date is older than four weeks:
$json = json_decode($result, true);
echo date("d.m.Y",strtotime($json[lastUpdated][when]));
$mydate = strtotime($json[lastUpdated][when]);
if ($mydate <= strtotime('4 weeks ago')) {
echo "Is not up to date!";
}
And I would like to have an output of how much time has passed between the date $mydate
and today. Thanks!
Upvotes: 1
Views: 41
Reputation: 8865
You could simply calculate the difference between both dates by using:
$mydate = strtotime($json['lastUpdated']['when']); // I guess the quotes are missing in your code
$now = time();
echo "The difference is " . ($now - $mydate) . " seconds";
If you need something different then seconds you'll have to calulcate those values, e.g.
echo "The difference is " . (($now - $mydate)/60) . " minutes";
echo "The difference is " . (($now - $mydate)/60*60) . " hours";
echo "The difference is " . (($now - $mydate)/60*60*24) . " days";
Upvotes: 2