Many solutions here did not account for rounding. For example:
Event happened at 3pm two days ago. If you are checking at 2pm, it will show one day ago. If you are checking at 4pm it will show two days ago.
If you are working with unix time, this helps:
// how long since event has passed in seconds
$secs = time() - $time_ago;
// how many seconds in a day
$sec_per_day = 60*60*24;
// days elapsed
$days_elapsed = floor($secs / $sec_per_day);
// how many seconds passed today
$today_seconds = date('G')*3600 + date('i') * 60 + date('s');
// how many seconds passed in the final day calculation
$remain_seconds = $secs % $sec_per_day;
if($today_seconds < $remain_seconds)
{
$days_elapsed++;
}
echo 'The event was '.$days_ago.' days ago.';
It is not perfect if you are worried about leap seconds and daylight savings time.