I have a SQL Datestamp like this: 2012-02-20 21:14:54
How would I print out the relative date and time in PHP?
e.g.
Occured: a few seconds ago
Occured: 4 minutes ago
Occured: 4 hours ago
Occured: Monday Jan 8th, 2012
After the hours I just want to print out the actual date
Found this after two seconds of Google http://www.mdj.us/web-development/php-programming/another-variation-on-the-time-ago-php-function-use-mysqls-datetime-field-type
In general you chose a unit of time like seconds, test if the time-difference is smaller then the max-value for this unit (60s) and if so, print out “$timeDifference $unit”. If not you divide the difference by the units max-value and start over with the next higher unit (minutes).
Example: