Function Reference: human time diff

Determines the difference between two timestamps.

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

Usage

human_time_diff( $from, $to );

Parameters

$from

(integer) (required) Unix timestamp from which the difference begins.

Default: None

$to

(integer) (optional) Unix timestamp to end the time difference. Default becomes time() if not set.

Default: ”

Return Values

(string)

Human readable time difference.

Examples

To print an entry’s time (“2 days ago”):

echo human_time_diff( get_the_time('U'), current_time('timestamp') ) . ' ago';

For comments:

echo human_time_diff( get_comment_time('U'), current_time('timestamp') ) . ' ago';

via Function Reference/human time diff « WordPress Codex.

Leave a comment