No... basically you said you MADE it... "I made this, it basically works abit like facebooks timer (under status' & posts etc..)".

No... basically you said you MADE it... "I made this, it basically works abit like facebooks timer (under status' & posts etc..)".
Now HotelUser, a spade isn't a spade!There's box shovels, round shovels, plumbers shovels, gardening shovels.
Well.. a spade's a spade I reckonnn!
Sorry, don't mean to bump, but this has broken now! :SThat's not what he asked for though, he wants to display the number of days, not seconds/minutes/hours.
That wouldn't work, it says time() - time().
I'd do this:
Untested and rushed, but should work.PHP Code:function plural($num) {
if ($num != 1)
return "s";
}
function getRelativeTime($date) {
$diff = time() - $date;
if ($diff<60)
return $diff . " second" . plural($diff) . " ago";
$diff = round($diff/60);
if ($diff<60)
return $diff . " minute" . plural($diff) . " ago";
$diff = round($diff/60);
if ($diff<24)
return $diff . " hour" . plural($diff) . " ago";
$diff = round($diff/24);
if ($diff<7)
return $diff . " day" . plural($diff) . " ago";
$diff = round($diff/7);
if ($diff<4)
return $diff . " week" . plural($diff) . " ago";
return "on " . date("F j, Y", strtotime($date));
}
// Unix timestamp for today at 17:21:19, replace this with a timestamp for whenever you want
$stampystamp = 1295803279;
// Display the number of seconds/minutes/hours/days/weeks since the timestamp
echo getRelativeTime($stampystamp);
It now displays 'on January 1, 1970' as the output.. any ideas?
Significance of that date in case it helps - http://en.wikipedia.org/wiki/January_1,_1970
Post the code that you're actually using.
Thanks, I haven't actually changed anything yet cos it's the same as was posted earlier. It was working originally..
PHP Code:function plural($num) {
if ($num != 1)
return "s";
}
function getRelativeTime($date) {
$diff = time() - $date;
if ($diff<60)
return $diff . " second" . plural($diff) . " ago";
$diff = round($diff/60);
if ($diff<60)
return $diff . " minute" . plural($diff) . " ago";
$diff = round($diff/60);
if ($diff<24)
return $diff . " hour" . plural($diff) . " ago";
$diff = round($diff/24);
if ($diff<7)
return $diff . " day" . plural($diff) . " ago";
$diff = round($diff/7);
if ($diff<4)
return $diff . " week" . plural($diff) . " ago";
return "on " . date("F j, Y", strtotime($date));
}
// Unix timestamp for today at 17:21:19, replace this with a timestamp for whenever you want
$stampystamp = 1295803279;
// Display the number of seconds/minutes/hours/days/weeks since the timestamp
echo getRelativeTime($stampystamp);
No. You've just posted the code that I posted. Post the code that you are using to call the function.PHP Code:function plural($num) {
if ($num != 1)
return "s";
}
function getRelativeTime($date) {
$diff = time() - $date;
if ($diff<60)
return $diff . " second" . plural($diff) . " ago";
$diff = round($diff/60);
if ($diff<60)
return $diff . " minute" . plural($diff) . " ago";
$diff = round($diff/60);
if ($diff<24)
return $diff . " hour" . plural($diff) . " ago";
$diff = round($diff/24);
if ($diff<7)
return $diff . " day" . plural($diff) . " ago";
$diff = round($diff/7);
if ($diff<4)
return $diff . " week" . plural($diff) . " ago";
return "on " . date("F j, Y", strtotime($date));
}
// Unix timestamp for today at 17:21:19, replace this with a timestamp for whenever you want
$stampystamp = 1295803279;
// Display the number of seconds/minutes/hours/days/weeks since the timestamp
echo getRelativeTime($stampystamp);
It should look a bit like this:
You've probably used a variable instead of that timestamp though, so post the code that you use to assign a value to the variable too.PHP Code:echo getRelativeTime(1295803279);
Want to hide these adverts? Register an account for free!