Here is a Twitter style PHP time interval calculation function that will return the time difference between two dates in days, hours, minutes or seconds depending on the time interval between the two times.
If the time interval is within 60 seconds, then ‘X seconds ago’ will be displayed. If the interval is between 60 seconds and 60 minutes then ‘X minutes ago’ will appear. Similarly, ‘X hours ago’ will be displayed for a time interval greater than 60 minutes but less than 24 hours and ‘X days ago’ for anything above 24 hours.
The time interval function takes in three arguments:
Here is the PHP time interval function:
The following example calls this function, passing 3 arguments for old date (MySQL datetime field from a recordset), new date (current time) and time type (x for automatic).
The resulting time string should appear as ‘X seconds ago’ or ‘X minutes ago’ etc depending on the time interval.