Calculating weekend discount hours

0

I'm implementing an application to check the time a data was created in the database. This date information is created by the native function of php time() which generates a value that is written to the database as string . In this check you have an alert when you go from 72 hours without this information, where I get the value of the string of the creation and add more the alert hours and check if the value is greater than the time() current. If greater, it has passed the treatment time. So far everything works normally. What happens and what do I need to deduct from check-in time on weekends, exactly 00:00 on Saturday until 11:59:59.

Would anyone have an idea how I can do this directly through the code? At the moment the only solution I envisioned was creating a pause time in the database with the initial and final values.

    
asked by anonymous 21.02.2018 / 19:15

1 answer

0

You can use strtotime to subtract hours from a pre-set date:

$data_final = strtotime('-1 day', strtotime($data_sem_descanso));

Edit, the code below returns the number of days of a month subtracting the days of rest:

function numDiasDescansoMes($mes, $ano, $diaDescanso1, $diaDescanso2=-1){

    $num_dias_mes = date("t", strtotime("01-$mes-$ano"));

    $n_dias_descanso = 0;

    for ($i = 1; $i <= $num_dias_mes; $i++){

        $data_loop = $i."-$mes-$ano";
        $dia_semana = date("w", strtotime($data_loop));
        if( ($dia_semana == $diaDescanso1) || ($dia_semana == $diaDescanso2) )
            $n_dias_descanso++;
    }

    return $num_dias_mes-$n_dias_descanso;

}

It's not quite what you want, but right now I'm going to be away. I think by the above code you can easily develop a function to do what you want.

    
21.02.2018 / 19:22