Show DevBest [PHP] 'Posted x ago' script

Status
Not open for further replies.

Markshall

Русский Стандарт
Contributor
Dec 18, 2010
2,637
2,389
Just a simple script that allows you to display how long ago a message was posted or whatever you need it for

Credits to me.

PHP:
<?php 
function agoDate( $date )
{ 
	$time_stamp = time() - strtotime( str_replace( "-", "/", $date ) ); 
	if( $time_stamp > 31536000 )
	{
		$ago = round( $time_stamp / 31536000, 0 ) . ' year';
	}
	elseif( $time_stamp > 2419200 )
	{
		$ago = round( $time_stamp / 2419200, 0 ) . ' month';
	}
	elseif( $time_stamp > 604800 )
	{
		$ago = round( $time_stamp / 604800, 0 ) . ' week';
	}
	elseif( $time_stamp > 86400 )
	{
		$ago = round( $time_stamp / 86400, 0 ) . ' day';
	}
	elseif( $time_stamp > 3600 )
	{
		$ago = round( $time_stamp / 3600, 0 ) . ' hour';
	}
	elseif( $time_stamp > 60 )
	{
		$ago = round( $time_stamp / 60, 0) . ' minute';
	}
	else
	{
		$ago = $time_stamp . ' second';
	}
	
	if( $ago > 1 )
	{
		$ago .= 's';
	}
	return $ago; 
} 
echo agoDate( "04-04-2011 12:04 pm" ) . " ago";
?>
 

Mastah

the funny thing is \r\n i did
Oct 25, 2010
739
41
wow awsome thanks for releasing all youre releases are awsome
 
Status
Not open for further replies.

Users who are viewing this thread

Top