Determines the difference between two timestamps.

The difference is returned in a human readable format such as “1 hour”, “5 mins”, “2 days”.

Signature

human_time_diff( $from, $to = '' )
from
 (int) Unix timestamp from which the difference begins.
to
 (int) Optional. Unix timestamp to end the time difference. Default becomes time() if not set.
Default: ''

Return

(string) Human readable time difference.

Source

function human_time_diff( $from, $to = '' ) {
	if ( empty( $to ) )
		$to = time();

	$diff = (int) abs( $to - $from );

	if ( $diff < HOUR_IN_SECONDS ) {
		$mins = round( $diff / MINUTE_IN_SECONDS );
		if ( $mins <= 1 )
			$mins = 1;
		/* translators: min=minute */
		$since = sprintf( _n( '%s min', '%s mins', $mins ), $mins );
	} elseif ( $diff < DAY_IN_SECONDS && $diff >= HOUR_IN_SECONDS ) {
		$hours = round( $diff / HOUR_IN_SECONDS );
		if ( $hours <= 1 )
			$hours = 1;
		$since = sprintf( _n( '%s hour', '%s hours', $hours ), $hours );
	} elseif ( $diff < WEEK_IN_SECONDS && $diff >= DAY_IN_SECONDS ) {
		$days = round( $diff / DAY_IN_SECONDS );
		if ( $days <= 1 )
21 more lines...
WP Trac GitHub

Link here