Last X Days Ago



Hire Us!Download Video(0)Comments
Need Jobs done? Use our brand new Jobs Board to get your projects done at affordable prices.


This tutorial will show you how to display those cool last seen 2 days ago or posted 3 mins ago as seen on http://www.live-tutorials.com

Example
This tutorial was written 220 days ago

Steps :
1. In this example we assume that you stored your time using the time() function. If not, then you can easily use strtotime().
We will create a function to make the calculation.

The above function checks the time and see if it is a day ago, minute or second. If you know a little time calculation then it should be easy to figure out. We divide by 3600*24( seconds in a day ) to see if it more than a day.

Next we get the time we want to see the difference. The tutorial was written today ( April 28 2008 ) which stipped to time would be ( 1209358800 ). To get the date difference we must now subtract the past date from the current time. In our tutorial, the past date would be (April 28 2008).

The codes below shows you how to wrap it all together and display the x time ago.

That's it. Now let us put it all together.

The result would be the following: This tutorial was written 220 days ago

 

Consider buying me coffee if you find this tutorial helpful.


Hire Us!Download Video(0)Comments
Need Jobs done? Use our brand new Jobs Board to get your projects done at affordable prices.