In facebook or twitter time of post is changing every minute on every post.

Any idea how to make it?

Edited by Acute: n/a

6 Years
Discussion Span
Last Post by steelshark

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.


You mean send AJAX request every minute to php function that gets date and counts the difference?


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.
So i think it would be better to use a javascript solution instead of Ajax.
You can write the date time to a hidden field, and use a javascript function to update every X seconds / minute / ...
Take a look at this link:
If you enhance this script a bit, you'll get the result you want, with much better performance.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.