PHP time ago calculation

The new web 2.0 displays time and date not in old style manner like 12.30 pm Jan 200 7. The new generation need relative time like 2 hours ago, 6 months ago, 4 years ago, very old etc. So if you save the timestamp of a particular content creation in database we can simply show this ‘ago time calculation’ using the following algorithm.

//$datefrom is the timestamp for the content , and you can leave the $dateto value to see the current delay

19 thoughts on “PHP time ago calculation

  1. Pingback: Fechas en formato tiempo transcurrido(time ago) con PHP - Bitácora de Webmaster

  2. joomla

    add one line “$datefrom = strtotime($datefrom);” right after “function TimeAgo($datefrom,$dateto=-1)
    {” to display your time properly. I was thinking what is missing, but as you mention above mention line, it will work fine…

    thanks for the great code!

Leave a Reply