Calculate a Time Difference String (seconds, minutes, hours, days) in PHP

This php function takes a timestamp and returns a detailed string of the time difference expressed in seconds, minutes, hours, days ago, or away if it’s in the future.

Examples

A timestamp 8 hours ago

Output

8 hours ago

A timestamp 18 hours ago

Output

2 weeks ago

Function