I need to change the timeformat in this column

to be in hours, not measured in seconds and minutes. This meaning that 30 minutes should be measured in 0.5 hours and so on.

I think I need to edit this line of code. Any suggestions on how to change the measurement to ONLY HOURS?

return human_time_diff(strtotime($item['time_login']), strtotime($item['time_last_seen']));

2 Answers 2


Welcome to WPSE.

You can try to filter it with:

add_filter( 'human_time_diff', 'wpse_hourly_human_time_diff', 10, 4 );

where the filter's callback is e.g.

 * Human time difference in hours only.
 * @param string $since The difference in human readable text.
 * @param int    $diff  The difference in seconds.
 * @param int    $from  Unix timestamp from which the difference begins.
 * @param int    $to    Unix timestamp to end the time difference.
function wpse_hourly_human_time_diff( $since, $diff, $from, $to ){
    return round( $diff / HOUR_IN_SECONDS, 1 );

but you will need to control where you want to apply this filter with:

remove_filter( 'human_time_diff', 'wpse_hourly_human_time_diff', 10 );

and further restrictions.

Hope you can adjust to your needs.


The human_time_diff() function is not going to work without modification.

Here's a working solution using simple PHP:

$login = '2020-09-28 10:00:00';
$last_seen = '2020-09-28 09:30:00';

$diff = strtotime($login) - strtotime($last_seen);

$hours = $diff / ( 60 * 60 );

return $hours;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.