Make a field in your database for each post, that records the time & date when it was posted.
Then you can make a function that returns the current datetime - the insertdatetime...
You round it off to whatever you want(ours, mins, seconds), and you just have to call that function than.
yeah...But it's not a very efficient solution though...To make that much database calls is not really good for the performance of your website.
If you enhance this script a bit, you'll get the result you want, with much better performance.