Last month I posted about a Human-friendly Time Ago PHP Function. Well, I’ve come across another way of doing it. This method has less code duplication, but is harder to understand at first glance. I prefer this method though, as it seems a bit more elegant than the other method. I’ve refined the code from the Stack Overflow post, and here’s what I have now.
Say you want to get the amount which has elapsed in a human-friendly format. Something like “27 minutes ago” or “3 days ago.” If you’re using WordPress, there is a handy function called human_time_diff() which does just that. But if you’re not using WordPress, here is a PHP function which will do the same.