Epoch seconds to "10 seconds ago", "2 minutes ago", "4 hours ago", etc

Posted on 2007-10-01
Last Modified: 2010-03-05
I'd like to be able to convert epoch seconds values into strings like:

"10 seconds ago"
"2 minutes ago"
"1 hour ago"
"4 days ago"
"3 weeks ago"
"2 months ago"

Can someone post the code to do this, or perhaps point me to a library that does this?

Question by:zumpoof
    LVL 17

    Accepted Solution

    See the Date::Manip module at  It's strength is doing things exactly like this...
    LVL 19

    Expert Comment

    This should help, but it wont work out if seconds are singular or plural etc
    LVL 17

    Expert Comment

    In the Date::Manip documentation, see especially the Delta_Format section, where you can express, say, 120 seconds in terms of minutes, and so on...
    LVL 84

    Expert Comment

    Will you ever want strings like "1 hour and 10 seconds ago"?
    Do you want to be able to define when we want to switch from using one unit to using another?

    Author Comment


    I just need it to be an approximation. The list I gave above is about as specific as I'd need.

    Featured Post

    Threat Intelligence Starter Resources

    Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

    Join & Write a Comment

    There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
    In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (…
    Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
    how to add IIS SMTP to handle application/Scanner relays into office 365.

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now