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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T00:58:24+00:00 2026-05-25T00:58:24+00:00

Possible Duplicates: Output is in seconds. convert to hh:mm:ss format in php How can

  • 0

Possible Duplicates:
Output is in seconds. convert to hh:mm:ss format in php
How can i display seconds ago/minutes ago/with unix timestamp?

I have this users online script I am working on. So far it is as follows…

while ($online_user = $q -> fetch(PDO::FETCH_ASSOC)) {

$last_active = time() - $online_user['online'];
echo '<p>' . $online_user['username'] . ' was last active ' . $last_active . ' seconds
    ago.</p>';

}

$online_user[‘online’] is the last time() the user was active on the website. So when I minus it from the current time() it gives me the amount of seconds ago that they were last active.

Thing is at the minute it echos like this:

Some username was last active 567 seconds ago.

I would like to know how I can make it echo so it would instead convert it to minutes and seconds so it would look something like this;

Some username was last active 9 minutes and 27 seconds ago.

Thanks in advance if you know of anywhere I could learn this please post a link. 🙂

  • 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-25T00:58:25+00:00Added an answer on May 25, 2026 at 12:58 am

    You can divide by 60 to get the number of minutes. The division remainder is the number of seconds not in a minute.

    $minutes = floor($last_active / 60);
    $seconds = $last_active % 60;
    echo 'Some username was last active ';
    
    if ($minutes > 0) {
        echo "$minutes minutes ";
    }
    
    if ($seconds > 0) {
        if ($minutes > 0) {
            echo "and ";
        }
        echo "$seconds seconds ";
    }
    echo "ago.";
    

    This will break it down into minutes and seconds, and won’t output the minutes or seconds if either is zero (ie. no “0 minutes and 30 seconds ago”. Note if you ever want to add hours (X hours, Y minutes, Z seconds), you can just take the same approach, dividing again by 60 (60 minutes per hour, 60 seconds per minute). To get ‘days’, you would divide by 24 (24 hours per day).

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

Sidebar

Related Questions

Possible Duplicates: Is String.Format as efficient as StringBuilder C# String output: format or concat?
Possible Duplicates: PHP headers already sent PHP session_start() error? What does this error mean?
Possible Duplicate: Can colorized output be captured via shell redirect? setup In this case
Possible Duplicate: Create Excel file in Java How to save output in excel format
Possible Duplicates: Why is lock(this) {...} bad? In C# it is common to use
Possible Duplicate: Default Number of Decimal Places to Output in PHP basically a bit
Possible Duplicate: How can I convert datetime microformat to local time in javascript? Im
Possible Duplicate: Can I use a generated variable name in PHP? Am stuck here!
Possible Duplicate: PHP DateTime::days returns trash? Ok, I don't get this... Could someone explain
Possible Duplicates: Changing c++ output without changing the main() function How to assign a

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.