When you are using human_time_diff
for convert time to human readable format. your last_visit
meta empty that is why it is return 50 years. so before convert human_time_diff
you have to check value is not empty. use below code to display last_login
, last_visit
.
$users = get_users();
foreach( $users as $user ) {
$udata = get_userdata( $user->ID );
$user_registered = $udata->user_registered;
$user_last_login = get_user_meta( $user->ID , 'last_login', true );
$user_last_seen = get_user_meta( $user->ID , 'last_visit', true );
$user_last_login = !empty($user_last_login) ? human_time_diff($user_last_login) : '-';
$user_last_seen = !empty($user_last_seen) ? human_time_diff($user_last_seen) : '-';
printf( '%s OD : %20s : Last Login : %20s : Last seen : %20s <br> ',
$udata->data->display_name,
date( "M Y", strtotime( $user_registered )),
$user_last_login ,
$user_last_seen
);
}