Link to home
Start Free TrialLog in
Avatar of rhinez0rz
rhinez0rz

asked on

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

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?
Avatar of rhinez0rz
rhinez0rz

ASKER

Nobody?
$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.
Figured it out myself:

SELECT UNIX_TIMESTAMP(upgrade_date) - UNIX_TIMESTAMP(now()) AS difference FROM tbl_resource);
ASKER CERTIFIED SOLUTION
Avatar of DarthMod
DarthMod
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial