Return to Snippet

Revision: 65637
at January 5, 2014 04:56 by KenanRecebli


Initial Code
<?php

function ago($time) {
	$diff = time() - (int)$time;

	if ($diff == 0) {
		return 'Just now';
	}

	$intervals = array(
		1 => array('year', 31556926),
		$diff < 31556926 => array('month', 2628000),
		$diff < 2629744 => array('week', 604800),
		$diff < 604800 => array('day', 86400),
		$diff < 86400 => array('hour', 3600),
		$diff < 3600 => array('minute', 60),
		$diff < 60 => array('second', 1)
	);

	$value = floor($diff/$intervals[1][1]);
	$ago = $value.' '.$intervals[1][0].($value > 1 ? 's' : '');

	$days = array('Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday');

	$day = $days[date('w', $time)];

	if ($ago == '1 day') {
		return 'Yesterday at '.date('H:i', $time);
	}
	elseif ($ago == '2 days' || $ago == '3 days' || $ago == '4 days' || $ago == '5 days' || $ago == '6 days' || $ago == '7 days') {
		return $day.' at '.date('H:i', $time);
	}
	elseif ($value <= 59 && $intervals[1][0] == 'second' ||  $intervals[1][0] == 'minute' ||  $intervals[1][0] == 'hour') {
		return $ago.' ago';
	}
	else {
		return date('M', $time).' '.date('d', $time).', '.date('Y', $time).' at '.date('H:i', $time);
	}
}

?>

Initial URL

                                

Initial Description
i dont see who is the author of this script, but i want to say him a lot thanks and would like to performance to him (and to everybody) a modification of this script.. i have modified it a bit and it is absolutely like on fb.. new "featchures" are:

instead - 
* 1-59 seconds, minutes, hours - nothing modified;
* 1 day ago: Yesterday at --:--
* 2-7 days ago: Monday (or other day of the week) at --:--
* 1 week ago etc.: Dec 27, 2013 at 22:06 (for example)

Initial Title
Facebok Style Timeago (advanced)

Initial Tags

                                

Initial Language
PHP