Posted By

jstnjns on 02/13/09

Statistics

Viewed 254 times
Favorited by 1 user(s)

Relative Time - Includes Future

/ Published in: PHP
`function relative_time(\$date) {	\$diff = time() - strtotime(\$date);	if (\$diff>0) {		if (\$diff<60)			return \$diff . " second" . plural(\$diff) . " ago";		\$diff = round(\$diff/60);		if (\$diff<60)			return \$diff . " minute" . plural(\$diff) . " ago";		\$diff = round(\$diff/60);		if (\$diff<24)			return \$diff . " hour" . plural(\$diff) . " ago";		\$diff = round(\$diff/24);		if (\$diff<7)			return \$diff . " day" . plural(\$diff) . " ago";		\$diff = round(\$diff/7);		if (\$diff<4)			return \$diff . " week" . plural(\$diff) . " ago";		return "on " . date("F j, Y", strtotime(\$date));	} else {		if (\$diff>-60)			return "in " . -\$diff . " second" . plural(\$diff);		\$diff = round(\$diff/60);		if (\$diff>-60)			return "in " . -\$diff . " minute" . plural(\$diff);		\$diff = round(\$diff/60);		if (\$diff>-24)			return "in " . -\$diff . " hour" . plural(\$diff);		\$diff = round(\$diff/24);		if (\$diff>-7)			return "in " . -\$diff . " day" . plural(\$diff);		\$diff = round(\$diff/7);		if (\$diff>-4)			return "in " . -\$diff . " week" . plural(\$diff);		return "on " . date("F j, Y", strtotime(\$date));	}}`