- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
function timeAgo($time_ago)
{
$time_ago = strtotime($time_ago);
$cur_time = strtotime(date('Y-m-d H:i:s'));
$time_elapsed = $cur_time - $time_ago;
$seconds = $time_elapsed;
$minutes = round($time_elapsed / 60);
$hours = round($time_elapsed / 3600);
$days = round($time_elapsed / 86400);
$weeks = round($time_elapsed / 604800);
$months = round($time_elapsed / 2600640);
$years = round($time_elapsed / 31207680);
if ($seconds <= 60) {
echo "$seconds seconds ago";
} else {
if ($minutes <= 60) {
if ($minutes == 1) {
echo "one minute ago";
} else {
echo "$minutes minutes ago";
}
} else {
if ($hours <= 24) {
if ($hours == 1) {
echo "an hour ago";
} else {
echo "$hours hours ago";
}
} else {
if ($days <= 7) {
if ($days == 1) {
echo "yesterday";
} else {
echo "$days days ago";
}
} else {
if ($weeks <= 4.3) {
if ($weeks == 1) {
echo "a week ago";
} else {
echo "$weeks weeks ago";
}
} else {
if ($months <= 12) {
if ($months == 1) {
echo "a month ago";
} else {
echo "$months months ago";
}
} else {
if ($years == 1) {
echo "one year ago";
} else {
echo "$years years ago";
}
}
}
}
}
}
}
}