Solved

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

Posted on 2006-07-22
5
139 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
  • 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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
mysql between clause 2 24
paypal ipn to mysql 3 37
send post values 7 26
PHP insert data in to database... this is not letting me in insert data...please help! 7 39
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.  …
Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
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…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

777 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