Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Hi ,
I have e.g. 15 days ago timestamp. Following function just returns no of days.
I want to know remaining no of mins, hours, days, weeks, year if any left.Code: Select all
$next_day_time = time() + (15 * 24 * 60 * 60); //15 is next third day timestamp
echo timeLeft($next_day_time);
function timeLeft($theTime)
{
$now = strtotime("now");
$timeLeft = $theTime - $now;
if($timeLeft > 0)
{
$days = floor($timeLeft/60/60/24);
$hours = $timeLeft/60/60%24;
$mins = $timeLeft/60%60;
$secs = $timeLeft%60;
if($days)
{
$theText = $days . " Day(s)";
if($hours)
{
$theText .= ", " .$hours . " Hour(s) ";
}
}
elseif($hours)
{
$theText = $hours . " Hour(s)";
if($mins)
{
$theText .= ", " .$mins . " Minute(s) ";
}
}
elseif($mins)
{
$theText = $mins . " Minute(s)";
if($secs)
{
$theText .= ", " .$secs . " Second(s) ";
}
}
elseif($secs)
{
$theText = $secs . " Second(s)";
}
}
else
{
$theText = "The time is already in the past!";
}
return $theText;
}feyd | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]