Support » Themes and Templates » Human Time Function Help

Human Time Function Help

  • sahaskatta


    I checked out the native human_time_diff function in WP, but I need some help.

    The example on that page is the following:
    <?php echo human_time_diff(get_the_time('U'), current_time('timestamp')) . ' ago'; ?>

    It shows the timestamp in relative to “days”. How can I tweak it to automatically switch between the following pseudocode:

    if time < 1 hour
    echo minutes
    elseif time < 1 day
    echo hours
    elseif time < 7 days
    echo days
    elseif time < 30 days
    echo weeks
    elseif time < 365 days
    echo months
    elseif time >- 365 days
    echo years

    I’m aware that there are plugins, but I’m trying to keep bloat minimal by writing a simple function that I can throw into functions.php. Could someone please give me a example of how to tweak that?

Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Human Time Function Help’ is closed to new replies.