convert time date to
a few second ago
about an hour ago
function convertToFBTimestamp( $d ) {
$d = ( is_string( $d ) ? strtotime( $d ) : $d ); // Date in Unix Time

if( ( time() – $d ) < 60 )
return ( time() – $d ).’ seconds ago’;
if( ( time() – $d ) < 120 )
return ‘about a minute ago’;
if( ( time() – $d ) < 3600 )
return (int) ( ( time() – $d ) / 60 ).’ minutes ago’;
if( ( time() – $d ) == 3600 )
return ’1 hour ago’;
if( date( ‘Ymd’ ) == date( ‘Ymd’ , $d ) )
return (int) ( ( time() – $d ) / 3600 ).’ hours ago’;
if( ( time() – $d ) < 86400 )
return ‘Yesterday at ‘.date( ‘g:ia’ , $d );
if( ( time() – $d ) < 259200 )
return date( ‘l \a\t g:ia’ , $d );
if( date( ‘Y’ ) == date( ‘Y’ , $d ) )
return date( ‘F, jS \a\t g:ia’ , $d );
return date( ‘j F Y \a\t g:ia’ , $d );
}

Leave a Reply