Solved

Showing difference between now() and a stored date in Mysql Table

Posted on 2006-07-22
5
143 Views
Last Modified: 2013-12-12
Howdy y'all

Got a 500 point question to the first buckeroo who can help me out here. Should be easy for some php pro; here goes:

Every time I "update" a record it updates a column called 'upgrade_time' with UNIX_TIMESTAMP()+1000, this works fine.

When I display the time 'till next upgrade, I want to show the time remaining between now() and whatever value is in upgrade_time in this format: days:hours:seconds. Can you show me how to do this?
0
Comment
Question by:rhinez0rz
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
5 Comments
 

Author Comment

by:rhinez0rz
ID: 17161967
Nobody?
0
 
LVL 10

Expert Comment

by:Khanh Doan
ID: 17162029
$timediff = TIMENOW - $timestamp;

if ($timediff < 3600)
{
      if ($timediff < 120)
      {
            $returndate = $vbphrase['1_minute_ago'];
      }
      else
      {
            $returndate = construct_phrase($vbphrase['x_minutes_ago'], intval($timediff / 60));
      }
}
else if ($timediff < 7200)
{
      $returndate = $vbphrase['1_hour_ago'];
}
else if ($timediff < 86400)
{
      $returndate = construct_phrase($vbphrase['x_hours_ago'], intval($timediff / 3600));
}
else if ($timediff < 172800)
{
      $returndate = $vbphrase['1_day_ago'];
}
else if ($timediff < 604800)
{
      $returndate = construct_phrase($vbphrase['x_days_ago'], intval($timediff / 86400));
}
else if ($timediff < 1209600)
{
      $returndate = $vbphrase['1_week_ago'];
}
else if ($timediff < 3024000)
{
      $returndate = construct_phrase($vbphrase['x_weeks_ago'], intval($timediff / 604900));
}

Try this

From function vbdate() of vBulletin
Bonmat86.
0
 

Author Comment

by:rhinez0rz
ID: 17162057
Figured it out myself:

SELECT UNIX_TIMESTAMP(upgrade_date) - UNIX_TIMESTAMP(now()) AS difference FROM tbl_resource);
0
 
LVL 1

Accepted Solution

by:
DarthMod earned 0 total points
ID: 17586561
PAQed with points refunded (500)

DarthMod
Community Support Moderator
0

Featured Post

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question