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?
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?
$timediff = TIMENOW - $timestamp;
if ($timediff < 3600)
{
if ($timediff < 120)
{
$returndate = $vbphrase['1_minute_ago'];
}
else
{
$returndate = construct_phrase($vbphrase ['x_minute s_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_a go'], 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.
if ($timediff < 3600)
{
if ($timediff < 120)
{
$returndate = $vbphrase['1_minute_ago'];
}
else
{
$returndate = construct_phrase($vbphrase
}
}
else if ($timediff < 7200)
{
$returndate = $vbphrase['1_hour_ago'];
}
else if ($timediff < 86400)
{
$returndate = construct_phrase($vbphrase
}
else if ($timediff < 172800)
{
$returndate = $vbphrase['1_day_ago'];
}
else if ($timediff < 604800)
{
$returndate = construct_phrase($vbphrase
}
else if ($timediff < 1209600)
{
$returndate = $vbphrase['1_week_ago'];
}
else if ($timediff < 3024000)
{
$returndate = construct_phrase($vbphrase
}
Try this
From function vbdate() of vBulletin
Bonmat86.
ASKER
Figured it out myself:
SELECT UNIX_TIMESTAMP(upgrade_dat e) - UNIX_TIMESTAMP(now()) AS difference FROM tbl_resource);
SELECT UNIX_TIMESTAMP(upgrade_dat
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER