Condition between weekdays

-1

Friends, I'm doing a little program that reads from a database between which days of the week a certain process must be executed.

I'm getting the day of the week based on date("N") and it gives me a number from 1-7, which would be, Monday, Tuesday, Wednesday, etc.

The issue is that making if($dia_inicio >= $dia_semana and $dia_semana <= $dia_termino) would only work within a week, but if you chose that the days to run will be from Saturday to Monday for example, it does not work for me.

I can not think of how to do it. If someone can give me some idea, I'm very grateful.

Greetings.

    
asked by Lusag silva 25.05.2018 в 01:19
source

1 answer

0

You could save in a list the days of the week that it is valid to execute the process. Then verify by checking if the current day is included in the list: in_array .

<?php
$dias_de_la_semana = array(6, 7, 1); // Sabado a Lunes

if (in_array(3, $dias_de_la_semana)) // Ejecutar Miercoles?
{
    echo "Ejecutar proceso";
}
?>

Now, to obtain the array of days of the week, based on two dates, I will leave here a bit of pseudocodigo:

dia_inicial = 3 // Miercoles
dia_final = 5 // Viernes

if dia_inicial <= dia_final
    for(i = dia_inicial; i <= dia_final; i++)
        dias_de_la_semana.push(i) // insertar en el array el numero de  dia
else
    for(i = 1; i <= dia_inicial; i++)
        dias_de_la_semana.push(i) // insertar en el array el numero de  dia
    for(i = dia_final; i <= 7; i++)
        dias_de_la_semana.push(i) // insertar en el array el numero de dia
    
answered by 25.05.2018 в 01:36