Solved

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

Posted on 2006-07-22
5
137 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
Comment Utility
Nobody?
0
 
LVL 10

Expert Comment

by:Khanh Doan
Comment Utility
$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
Comment Utility
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
Comment Utility
PAQed with points refunded (500)

DarthMod
Community Support Moderator
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
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…
The viewer will learn how to dynamically set the form action using jQuery.

763 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now