I have a code
echo date('d-m-Y H:i', strtotime($posts_row['post_date'])) . '</td></tr>';
The result:
23-10-2013 16:28
Is there a way to change into like:
Posted 12 minutes ago
or / &
Just Posted
Whats the easiest way of doing this?
I have a code
echo date('d-m-Y H:i', strtotime($posts_row['post_date'])) . '</td></tr>';
The result:
23-10-2013 16:28
Is there a way to change into like:
Posted 12 minutes ago
or / &
Just Posted
Whats the easiest way of doing this?
To fetch the difference of seconds between current time and posted time:
$number_of_seconds = strtotime("now") - strtotime($posts_row['post_date']);
Then, you can apply your logic to display how many seconds ago, just now, etc.
strtotime will help you to convert the date and make operations over it.
function elapsedTimeAgo ($newTime) {
$timeCalc = time() – strtotime($newTime);
$elapsedTimeText = "";
if ($timeCalc > (60*60*24)) {
$elapsedTimeText = round($timeCalc/60/60/24) . "days ago";
} else if ($timeCalc > (60*60)) {
$elapsedTimeText = round($timeCalc/60/60) . "hours ago";
} else if ($timeCalc > 60) {
$elapsedTimeText = round($timeCalc/60) . "minutes ago";
} else if ($timeCalc > 0) {
$elapsedTimeText .= "seconds ago";
} else {
$elapsedTimeText .= "Just Posted";
}
return $elapsedTimeText;
}
echo elapsedTimeAgo($posts_row['post_date']);