I know this has been asked several times before but I can't seem to find the right answer. I want to calculate the difference between two unix timestamps and show this difference in days. I'm not concerned about minutes or seconds here.
$time = 172800 - time() + 1265010604;
echo floor($time/86400);
Where 1265010604 is the timestamp for today and 172800 is a 3 day offset. Thanks
$now = time();
$then = time() - 172800;
$difference = $now - $then;
echo "It was ".floor($difference / 86400)." days ago";
I want to calculate the difference between two unix timestamps and show this difference in days
This sentence captures your requirements and suggests a straightforward approach:
$difference = abs($t0 - $t1);
$days = floor($difference / 86400);
/* First second of the day */
function dayStart ($date) {
return mktime(0, 0, 0, date('n', $date), date('j', $date), date('Y', $date));
}
/* Get count of days between dates */
function daysBetween ($dateStart, $dateEnd) {
return round((dayStart($dateEnd) - dayStart($dateStart)) / (24 * 60 * 60));
}