Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8044069
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T05:06:40+00:00 2026-06-05T05:06:40+00:00

I want to implement a functionality for my project. It’s very similar to a

  • 0

I want to implement a functionality for my project. It’s very similar to a feature on Stack Overflow where user post requests and gets responses. Here on Stack Overflow we see post marked as 4 seconds ago, 22 seconds ago, 1 minute ago, 5 minutes ago etc. I want to implement the same.

I am storing the request posted time in a timestamp variable in MySQL, then subtracting NOW() - stored_time to get the seconds. Then writing some logic, like

  • if less than 60 seconds, display 60 seconds ago
  • if difference in between 60 to 3600, display in minutes

and so on. This long logic is written in Perl. I want to avoid that. Is there any good way to achieve the same thing? I am open to change the MySQL table and data type.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T05:06:42+00:00Added an answer on June 5, 2026 at 5:06 am

    Retrieve the datestamps as DateTime objects. You don’t show any details of your database, so I have to skip that step in my answer.

    use DateTime qw();
    use DateTime::Format::Human::Duration qw();
    
    for my $seconds (555, 5555, 555555, 5555555) {
        my $now = DateTime->now;
        my $before = $now->clone->subtract(seconds => $seconds);
        my $formatted = DateTime::Format::Human::Duration
            ->new->format_duration($before - $now);
        $formatted =~ s/(?:,| and).*//;
        print "about $formatted ago\n";
    }
    
    # about 9 minutes ago
    # about 1 hour ago
    # about 6 days ago
    # about 2 months ago
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to implement functionality which let user share posts by other users similar
I want to implement functionality like back and forward in my project same as
I want to implement search functionality for a website (assume it is similar to
I'm developing own CMS and i want to implement functionality to dynamically include existing
i want to implement next previous functionality using below function. - (void)motionEnded:(UIEventSubtype)mt withEvent:(UIEvent *)event
I want to implement simple LINQ-to-SQL-like functionality in my .net application. For example i
I want to use an external browser window to implement a preview functionality in
I want to implement an autocomplete feature with images in my website. I would
I want to implement the 'Update' functionality for one of my .NET application. I
I'm trying to implement change password functionality in Symfony 2 project. I have entity

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.