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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T22:21:49+00:00 2026-05-23T22:21:49+00:00

In my MySQL table I have a datatime column (the time is saved in

  • 0

In my MySQL table I have a datatime column (the time is saved in the following format 2011-02-15 11:01:14). I extract this information with the PHP and print it to the user page.

$results = mysql_query($cmd,$link);
while ($res_array = mysql_fetch_array($results)) {
   $submitted_at = $res_array['datetime'];
   print $submitted_at."<br>";
}

However, I would like to show not only the given datatime, but also how long ago it was. In more detail, I need something like that: (67 day 4 hours 47 minutes 7 seconds ago). Does PHP have some functions that can make it easier. In particular I bother with the fact that month could have 28, 29, 30 and 31 days.

As an alternative, I thought about doing it on the MySQL level. It should be easy to extract the number of second from the given time to the current data. Then I can easilly transform seconds into days, hours and minutes. But I do not know how can I access this information using the mysql_fetch_array. Should it be something like $res_array['unix_timestamp(now())-unix_timestamp(datatime)']?

  • 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-23T22:21:50+00:00Added an answer on May 23, 2026 at 10:21 pm

    This’ll be what you’re looking for just change the formatting to suit your needs.

    http://php.net/manual/en/datetime.diff.php

    For example:

    <?php
    $datetime1 = date_create('2009-10-11');
    $datetime2 = date_create('2009-10-13');
    $interval = date_diff($datetime1, $datetime2);
    echo $interval->format('%R%a days');
    ?>
    

    Change this line:

    $interval->format(‘%R%a days’)

    Following guidelines from here:

    http://php.net/manual/en/function.date.php

    Edit: This function is PHP 5.3+

    Edit2 : Found this for older versions of PHP
    How to calculate the difference between two dates using PHP?

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

Sidebar

Related Questions

I have mysql table that has a column that stores xml as a string.
I have a mysql table that relies on the unix epoch time stamp equivalent
Possible Duplicate: Datetime vs Timestamp? I have a Mysql table, which has a column
I have a MySQL db with a table containing a datetime column. However, I
All, I have a MYSQL table with a column called timestamp. It is of
I have a table that contains a Date column in varchar format. The date
I have a MySQL table with a datetime column named 'created' which contains the
I have the following tables category and category_description in php mysql. my question is
I have a mysql database table that gets the datetime column automatically filled when
I have a last_notified column on my MySQL table, data type DATETIME I want

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.