jeudi 22 novembre 2018

Get delay hours and extra hours using Carbon library in Laravel

I'm working on a attendance report and need to display the delay and overtime hours times using carbon , I'm calculation the difference between time In and TimeOut, then subtract 1 hour (lunch hour) , i have problem subtracting 1 hour.

Second , once the above is ready I need to calculate the real employee arrival and departure times and get the difference to get hours worked.

      $timeIn = Carbon::createFromFormat('H:i', $hra_entrada_m); //08:00 am
      $timeOut = Carbon::createFromFormat('H:i', $hra_salida_t);  //17:30 pm

      $time1 =  $timeIn->diff($timeOut);          <- 9:30
      $time1 =  $time->subtract(60, 'minutes');     <- problem   
      return  $time1->format('%H:%i');            ->should display 8:30


      $employeeTimeIn = Carbon::createFromFormat('H:i', $emp_time_in); //08:15 am
      $employeeTimeOut = Carbon::createFromFormat('H:i', $emp_time_out); //17:40 pm
      $time2 =  $employeeTimeIn->diff($employeeTimeOut);  

now to get diference between time1 and time2 i want to convert them in milliseconds,

      $hours_worked = ($time1->milliseconds() - $time2->milliseconds() )

thanks in advance



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire