This is a short reusable coding snippet that could save you some programming time. I was creating one for myself, and later figured out I would put it up here on my blog as well, in case someone needs it.
The objective is to take in a date as input and then provide the date difference in a meaningful way. For example, if the difference is few seconds, it should say "A moment ago", instead of 17.563 seconds. Also it makes sense to say "Yesterday", instead of "27.75 hours ago". The script below is created using such assumption.