Calculation in% between PHP time loads

1

I need to calculate the adhesion between two workloads.

  • Load 1: Load carried out is the end time - the start time
  • Load 2: Scheduled load is the scheduled end time - the scheduled start time.

I gave a print in the data:

Realizado: 2016-10-24 15:10:00 - 2016-10-24 07:39:12 = Carga1: 07:30:48
Programado: 15:10:00 - 07:00:00 = Carga2: 08:10:00
Percentual: 0.875

* The format of the realized comes with date and the programmed only the time, I tried to leave both in the same format but did not work.

I'm going down this path:

$date1 = strtotime($ponto_inicio);
$date2 = strtotime($ponto_fim);
$realizado = date( 'H:i:s', abs( $date2 - $date1 ) );

$date3 = strtotime($hora_inicio);
$date4 = strtotime($hora_fim);
$programado = date( 'H:i:s', abs( $date4 - $date3 ) );

$percentual =  $realizado / $programado;

The results of 100% are ok but when it comes out the result is always 0.95 por exemplo for cases of the same and different programmed time.

What's wrong?

    
asked by anonymous 25.10.2016 / 15:04

2 answers

1

Hello! Try:

$percentual = ($realizado * 100)/$programado;
    
25.10.2016 / 15:11
0

I achieved the result by converting the loads to seconds, using date_paser();

$date1 = strtotime($ponto_inicio);
$date2 = strtotime($ponto_fim);
$realizado = date( 'H:i:s', abs( $date2 - $date1 ) );
$realizado = date_parse($realizado);
$realizado = $realizado['hour'] * 3600 + $realizado['minute'] * 60 + $realizado['second'];

$date3 = strtotime($hora_inicio);
$date4 = strtotime($hora_fim);
$programado = date( 'H:i:s', abs( $date4 - $date3 ) );
$programado = date_parse($programado);
$programado = $programado['hour'] * 3600 + $programado['minute'] * 60 + $programado['second'];

$percentual =  $realizado / $programado;

In this way the percentage came out right, I do not know if the structure is completely correct.

    
25.10.2016 / 16:44