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 6776897
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T16:05:00+00:00 2026-05-26T16:05:00+00:00

What would be a good way to get the time elapsed for a tuple

  • 0

What would be a good way to get the time elapsed for a tuple from a database like Stackoverflow or Facebook does? When < 1 minute elapsed display seconds elapsed, less than 1 hour display minutes etc. Can this be in MySQL with better performance than formatting in PHP?

  • 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-05-26T16:05:01+00:00Added an answer on May 26, 2026 at 4:05 pm

    No. This PHP really best suited – you can get timestamp value from the database and (eventually) convert it into Unix epoch format like that:

    SELECT UNIX_TIMESTAMP(`when`) FROM `posts` ORDER BY `id` DESC LIMIT 1;
    

    and then calculate the difference. Calculating the difference, especially when dividing it into ranges, you would require MySQL to do something that is not really best suited for that.

    Eventually you can also think about passing processing effort to the user – just try using JavaScript to determine the difference based on the timestamp. That way you can just use PHP to display value from database, without further processing on PHP’s side.

    Solution using JavaScript (jQuery)

    This solution shifts processing effort into user and allows for constant updating of the timestamp at the same time. JavaScript could look like this:

    jQuery('span[data-timestamp]').each(function(){
        var el = jQuery(this);
        var then = Math.floor(el.attr('data-timestamp'));
        var updateTime = function(){
            var now = Math.floor((new Date()) / 1000);
            el.html((now - then) + ' seconds ago');
        };
        setInterval(updateTime, 1000);
        updateTime();
    });
    

    and then every snippet looking like that:

    <span data-timestamp="1320821800"></span>
    

    will be converted into relative timestamp and updated every second (see this jsfiddle). If you want to use it, just make sure updateTime properly changes relative timestamp in seconds into one employing different units (minutes, hours, days, weeks, months, years etc. …).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

What is a good way to run a time-consuming function from a C# webpage
What would be a good way to determine if a string contains an IPv4
What would be a good way to writein C# a .NET3.5 Thread Safe DataSource
What is a good way to perform animation using .NET? I would prefer not
Thinking in regards to Sliverlight, I would like to know where would be good
What would be a good way to solve the following problem in Qt: I
Simply because I worry about abusing AJAX to get real-time functionality. Seems like there
Ok, so I'm having a hard time coming up with a 'good' way to
What is a good way to get a reference to singleton objects in Objective-C?
What would be a good way to use Boost in a small team (<

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.