How to calculate relative time like facebook

I've found this cool snippet witch returns the relative time from a given date.

Just like facebook does posted 20 minutes ago.

You can translate it from English to any language. Just make sure you edit the $periods array.

  • Genius… Will try to apply it on an iPhone app… thanks

  • HI, GOOD CODE this is using foreach

  • In order to add an “s” to the end of the current period, it looks as though you may want to move the

    logic to just AFTER the

    loop. Otherwise it seems to only add plural endings to all periods prior to the one that really matters.

Leave a Reply

Add <code> Some Code </code> by using this tags.