Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2006-07-22
5
Medium Priority
?
146 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

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…
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
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…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

885 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