Hey guys, I found this function on the internet and I'm learning PHP :S (apparently not very well yet) I would like to use it to display relative text to dates like: Yesterday, Today...etc instead of the actuall date from the DB table "2009-12-01 12:53:12".
Anyways... I tried several syntaxes :S
$time = $row_replyList['reply_date'];
function relative_date (strtotime($time)){echo $time;};
$time = $row_replyList['reply_date'];
function relative_date (strtotime($time)){
return $time;
}
echo $time;
$time = $row_replyList['reply_date'];
function relative_date (strtotime($time));
echo $time;
$time = function relative_date (strtotime($row_replyList['reply_date'])); echo $time;
But none worked :S
It keeps returning me errors. Does anybody knows what am I doing wrong please?
I'm terribly sorry to bother with a question like that..(It might be easy for you guys, but I don't understand functions very well :S)
Heres the code of the function:
<?php
//Relative Date Function
function relative_date($time) {
$today = strtotime(date('M j, Y'));
$reldays = ($time - $today)/86400;
if ($reldays >= 0 && $reldays < 1) {
return 'Today';
} else if ($reldays >= 1 && $reldays < 2) {
return 'Tomorrow';
} else if ($reldays >= -1 && $reldays < 0) {
return 'Yesterday';
}
if (abs($reldays) < 7) {
if ($reldays > 0) {
$reldays = floor($reldays);
return 'In ' . $reldays . ' day' . ($reldays != 1 ? 's' : '');
} else {
$reldays = abs(floor($reldays));
return $reldays . ' day' . ($reldays != 1 ? 's' : '') . ' ago';
}
}
if (abs($reldays) < 182) {
return date('l, j F',$time ? $time : time());
} else {
return date('l, j F, Y',$time ? $time : time());
}
}
?>