add in bd a date 2 days after today without counting saturday and sunday in mysql php

0

I have an insert in mysql database of dates,

I am using the date_sub command to add 4 days to the current date,

    $fecha_actual = now();
    INSERT INTO TABLA_FECHAS (preparar, llamar) VALUES 
(' . $fecha_actual .',date_sub(' . $fecha_actual .',INTERVAL 2 DAY)),

I need that if the current $ date is Friday when doing the insert into, do not count the day Saturday or Sunday, that is to say when inserting the call field, you must add 2 days to Friday but without counting Saturday and Sunday. It should be on Tuesday.

what date_sub command I can add so it does not count on Saturday or Sunday.

    
asked by Ivan Diaz Perez 08.02.2018 в 20:05
source

1 answer

4


I think what you have to use at this point is the function DAYOFWEEK() in conjunction with an if, in addition, to add days you have to use the function date_add instead of date_sub:

INSERT INTO TABLA_FECHAS (preparar, llamar)
VALUES (
    '$fecha_actual',
    IF( DAYOFWEEK('$fecha_actual')=6,
        DATE_ADD('$fecha_actual',INTERVAL 4 DAY),
        DATE_ADD('$fecha_actual',INTERVAL 2 DAY)
    )
);
    
answered by 08.02.2018 / 20:20
source