WordPress.org

Ready to get started?Download WordPress

Codex

Attention Interested in functions, hooks, classes, or methods? Check out the new WordPress Code Reference!

Function Reference/human time diff

Description

Determines the difference between two timestamps.

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

Usage

<?php 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"): <?php echo human_time_diffget_the_time('U'), current_time('timestamp') ) . ' ago'?> For comments: <?php echo human_time_diffget_comment_time('U'), current_time('timestamp') ) . ' ago'?>

Notes

Change Log

Since: 1.5.0

Source File

human_time_diff() is located in wp-includes/formatting.php.

Related

Time Functions: current_time(), human_time_diff(), the_time(), get_the_time(), comment_time()

See also index of Function Reference and index of Template Tags.