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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T05:23:42+00:00 2026-05-24T05:23:42+00:00

I’m working with a function I found to do this, but I’m trying to

  • 0

I’m working with a function I found to do this, but I’m trying to make it work with a GMT utc timestamp:

EDIT:
Maybe my issue is with how i’m “converting” the user input time to GMT…

I was doing

$the_user_input_date = strtotime('2011-07-20T01:13:00');
$utctime = gmdate('Y-m-d H:i:s',$the_user_input_date);

Does gmdate('Y-m-d H:i:s',$the_user_input_date); not actually “convert” it to gmt? does it just format it? Maybe thats my issue.

Here’s what the times I can supply would look like:

//local time in GMT
2011-07-20T01:13:00

//future time in GMT
2011-07-20T19:49:39

I’m trying to get this to work like:

    Started 36 mins ago
    Will start in 33 mins
    Will start in 6 hrs 21 mins
    Will start in 4 days 4 hrs 33 mins

Here’s what im working with so far:

EDIT: new php code im working with, seems to ADD 10 HOURS on to my date. Any ideas? I  updated it here:

function ago($from)
 {
  $to = time();

  $to = (($to === null) ? (time()) : ($to));
  $to = ((is_int($to)) ? ($to) : (strtotime($to)));
  $from = ((is_int($from)) ? ($from) : (strtotime($from)));

  $units = array
  (
   "year"   => 29030400, // seconds in a year   (12 months)
   "month"  => 2419200,  // seconds in a month  (4 weeks)
   "week"   => 604800,   // seconds in a week   (7 days)
   "day"    => 86400,    // seconds in a day    (24 hours)
   "hour"   => 3600,     // seconds in an hour  (60 minutes)
   "minute" => 60,       // seconds in a minute (60 seconds)
   "second" => 1         // 1 second
  );

  $diff = abs($from - $to);
  $suffix = (($from > $to) ? ("from now") : ("ago"));

  foreach($units as $unit => $mult)
   if($diff >= $mult)
   {
    $and = (($mult != 1) ? ("") : ("and "));
    $output .= ", ".$and.intval($diff / $mult)." ".$unit.((intval($diff / $mult) == 1) ? ("") : ("s"));
    $diff -= intval($diff / $mult) * $mult;
   }
  $output .= " ".$suffix;
  $output = substr($output, strlen(", "));

  return $output;
 }

@Jason

I tried what you suggested here:

function ago($dateto)
    {
      $datetime1 = new DateTime( $dateto);
      $datetime2 = new DateTime();
      $interval = $datetime1->diff($datetime2);
      // print_r($interval);

      $format = '';
      if ($interval->h) {
              $format .= ' %h ' . ($interval->h == 1 ? 'hour' : 'hours');
      }
      if ($interval->i) {
              $format .= ' %i ' . ($interval->i == 1 ? 'minute' : 'minutes');
      }
      // more logic for each interval

      if ($format) {
              echo $interval->format($format), ' ago';
      }
      else {
              echo 'now';
      }
    }

It always seems to add 10 hours on to my time.

Any ideas what could be going on?

Maybe an error lies with how I’m saving the target time?
When someone submits a time its converted and stored like this

The user submitted time will always start out looking like this as their local time:
07/20/2011 11:00 pm

Then:

$time = mysql_real_escape_string($_POST['time']);

$the_date = strtotime($time);

//make user input time into GMT time
$utctime = gmdate('Y/m/d H:i:s',$the_date);

$query = "INSERT INTO $table (time) VALUES ('$utctime');";
mysql_query($query);
  • 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-24T05:23:43+00:00Added an answer on May 24, 2026 at 5:23 am

    Provided you have access to PHP >= 5.3 I’d recommend DateTime::diff(). The DateInterval returned gives you all the parts you would need for display as well as has its own methods, such as format().

    Here’s a sample to give you an idea. There are more complete samples in the comments of the PHP documentation links.

    <?php
    $datetime1 = new DateTime('2011-07-20');
    $datetime2 = new DateTime();
    $interval = $datetime1->diff($datetime2);
    // print_r($interval);
    
    $format = '';
    if ($interval->h) {
            $format .= ' %h ' . ($interval->h == 1 ? 'hour' : 'hours');
    }
    if ($interval->i) {
            $format .= ' %i ' . ($interval->i == 1 ? 'minute' : 'minutes');
    }
    // more logic for each interval
    
    if ($format) {
            echo $interval->format($format), ' ago';
    }
    else {
            echo 'now';
    }
    

    It outputs (on my system):

    22 hours 10 minutes ago

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I want to construct a data frame in an Rcpp function, but when I
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
this is what i have right now Drawing an RSS feed into the php,
Seemingly simple, but I cannot find anything relevant on the web. What is the

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.