3
I need to calculate the exact time that a given record has to be analyzed.
Each registration has a intermission where it can be analysed and, a maximum value in hours, referring to deadline for analysis.
Example
End time = Registration date + Deadline = 26/12/2014 04:24:31
But I need the off-hours to be ignored, which means:
- The day 25 would be counted only 01:35:29, because the interval is until 22h
- It would return the count from 08h, finalizing the exact time 26/12/2014 14:24:31
My current solution is a loop
for each record:
$incremento = 0
$cadastro = "26/12/2014 04:24:31"
$intervalo_inicial = 8
$intervalo_final = 10
$prazo = 8
while ($incremento <> $prazo) {
if ($cadastro >= $intervalo_inicial) and ($cadastro <= $intervalo_final) {
$incremento += 1
}
// adiciona 1 hora
$cadastro = date($cadastro, strtotime('1 hour'));
}
However, calculating 100,000 record makes the task very slow. Any type of solution is valid, database, formula, logic..
Perfect @hugomg, just changed the
$dias_gastos = $prazo/24
, in some situations was counting +1 day– Lucio Rubens
Which cases were giving the wrong value? Dividing by 24 you do not ignore the hours out of range...
– hugomg