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.
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";
?>