• I’m using the function human_time_diff (<?php echo human_time_diff( get_the_time('U'), current_time('timestamp') ); ?>) on a site, but it’s returning a completely wrong time. It should say something like 1 hour ago, but it’s returning 18 hours ago. Why is it off?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Hi @breathelifein,

    are you using this on a basic page, not the blog page? If yes, I assume that your time is the exact time when your page is created.

    I needed to do a post lift to front page and it also gave me a wrong time. I did a small change to function I’m using:

    function kk_humantime( $id = '' ){
    
    	if( $id == '' ) {
    		printf( __( '%s ago', 'your-text-domain' ), human_time_diff( get_the_time( 'U' ), current_time( 'timestamp' ) ) );
    	} else {
    		printf( __( '%s ago', 'your-text-domain' ), human_time_diff( get_the_time( 'U', $id ), current_time( 'timestamp' ) ) );
    	}
    }

    After that I can call the function with a post id to get the right time.

    Hope that helps! 🙂

    Thread Starter breathelifein

    (@biellebrunner)

    Hi, @tjakonen. Thanks for replying.
    But it didn’t work. I need to get the page ID and replace on that function you posted (and put it on functions.php), right?
    But I’m still getting the wrong date.

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘human time diff giving me the wrong time’ is closed to new replies.