well, first let's fix the function itself, then find the error you mean.
Code: Select all
<?php
function displaytime($postedtime, $time) {
$diff = $time - $postedtime;
if ($diff < 60) {
return date("s", $diff) . " seconds ago";
}
elseif ($diff < 3600) {
return date("i", $diff) . " minutes ago";
}
elseif ($diff < 86400) {
return date("H", $diff) . " hours ago";
}
elseif ($diff < ????????) {
return date("d", $diff) . " days ago";
}
else {
return "Older Than 1 Month";
}
}
?>
If it skips the one elseif statement, then obviously it evaluated to false--you don't need to check it again.
On the last, it would always say how many days old it was. You had 'if $diff is greater than one day.' You need to check if it's smaller than a month. As I said before, if it's parsing said statement, it already knows it's greater than a day.
also, you should space your code out a bit more--kinda hard to read.
if you like shorter code, then you don't really need the brackets:
Code: Select all
<?php
function displaytime($postedtime, $time) {
$diff = $time - $postedtime;
if ($diff < 60) return date("s", $diff) . " seconds ago";
elseif ($diff < 3600) return date("i", $diff) . " minutes ago";
elseif ($diff < 86400) return date("H", $diff) . " hours ago";
elseif ($diff < ????????) return date("d", $diff) . " days ago";
else return "Older Than 1 Month";
}
?>