Insert 3 more days to the current date add Saturday and Sunday

0

I have this in php mysql

$fechaactual = Date("Y-m-d");
tep_db_query(
      "UPDATE " 
    . TABLE_ENTREGAS 
    . " SET fecha_calidad = DATE_ADD('" 
    . tep_db_input($fechaactual) 
    . "', INTERVAL 3 DAY) WHERE numero_contrato = '" 
    . $contrato['numero_contrato'] 
    . "'"
); 

and I need that if it's Thursday, add 1 more day to the 3 days of the programmed interval and if it is Friday add 2 more days to the 3 days of the programmed interval set in fecha_calidad .

that is, if Thursday is day 08/03/2018 when doing the update on Thursday the quality_date should be 1 day + 3 days of the interval = 4 days in fecha_calidad

that is to say if Friday is day 09/03/2018 when doing the update on Friday the date_quality should be 2 days (Saturday and Sunday) + 3 days of the interval = 5 days in fecha_calidad

as would be the query to recognize the sum of 4 days if it is Thursday how would the query be for recognizing the sum of 5 days if it is Friday

In conclusion, you should never make a update to fecha_calidad on Saturday or Sunday.

    
asked by Ivan Diaz Perez 06.03.2018 в 12:52
source

1 answer

1

Why not use DateTime to know the day of the week and use a conditional.

Example:

<?php
$fecha = new DateTime('now');
$diaSemana = $fecha->format('N');
$fechaactual = $fecha->format('Y-m-d');

if ($diaSemana == 4){ // Jueves
        tep_db_query("UPDATE " . TABLE_ENTREGAS . " SET fecha_calidad = DATE_ADD('" . tep_db_input($fechaactual) . "', INTERVAL 4 DAY) WHERE numero_contrato = '" . $contrato['numero_contrato'] . "'");
} elseif ($diaSemana == 5){ // Viernes
    // hacer lo que corresponda el Viernes
} else { 
    // hacer lo que corresponda el si no es ni Jueves ni Viernes
}
    
answered by 06.03.2018 / 13:51
source