To print relative time on posts automatically we can use get_the_date
filter. We will check the time difference and print it in human readable form.
// Relative date & time
function wp_relative_date() {
return human_time_diff( get_the_time('U'), current_time( 'timestamp' ) ) . ' ago';
}
add_filter( 'get_the_date', 'wp_relative_date' ); // for posts
add_filter( 'get_comment_date', 'wp_relative_date' ); // for comments
And in your theme use <?php echo get_the_date(); ?>
to print relative time.
If you do not need relative time for comments then remove following from code.
add_filter( 'get_comment_date', 'wp_relative_date' ); // for comments
EDIT
To get time difference in seconds. Use this.
$seconds = current_time( 'timestamp' ) - get_the_time('U');
Now you can use $seconds
in your if conditions.