Getting last event per day from mysql database with CodeIgniter

we have a CRM Application to monitor employees check ins and check outs of every location (clients)

I’m requested to get the last check out of a specific employee per day.

My database looks like this:

| employee_id | check in time | check out time |
| ———– | ————- | ————– |
| 90 | 1666536812 | 1666537080 |
| 90 | 1653467778 | 1653474758 |
| 90 | 1653467444 | 1653474321 |
….

Every employee has multiple check outs per day, i need to get the last one per day.

My attempt so far:

$this->db->order_by('check_out_time desc');
$this->db->where('employee_id', $user_id);
$query = $this->db->get('events',50);

foreach($events as $event){
   // Change event(check out) time from epoch format to normal format
   $checkOutTime = new DateTime("@".$event->check_out_time);
   $event->check_out_time = $checkOutTime->format('Y-m-d H:i:s');

   // get day if this event
   $day =$checkOutTime->format('Y-m-d');

   // set the "visits[day] to max value of that day
   if (!isset($visits[$day]) || $visits[$day] < $event->check_out_time )
      $visits[$day] = $event->check_out_time;
}

Output:
enter image description here

the output is visually what i want but the data is incorrect