Combine If in PHP with Time

0

I am modifying a reservation system and I want it not to be reserved for more than 24 or 48 hours in advance. Currently when it is Monday, with the following code I can make reservations for the whole week:

Resuelto

Right now the only thing he does is once 30 minutes have passed since the beginning of the reservation, he can not book.

The part would be this but I can not do it

if($n_dia==$i && $clase_celda->int_hora <= $n_hora)

I'm also trying to combine it with that if the variable <?=$cliente->caducidad?> is < that the current date does not leave you either but I do not know if I have to do them separately or you can use & amp; or the OR or AND

Here what it does is not show the booking button when the current time is

asked by Jesús 02.09.2018 в 03:51
source

2 answers

1

In the end I managed to make it work in the following way:

//Seleccionamos fecha de caducidad del cliente.
$caducidad_01 = ($cliente->caducidad);
$caducidad_02 = str_replace('/', '-', $caducidad_01);
$caducidad_final = date("Y-m-d", strtotime($caducidad_02));

//Limitamos los días de reserva
$hoy = date("Y-m-d");
$limite_reserva = date('Y-m-d',strtotime($hoy . "+2 days"));

And then I've put the following ifs

if($dia['fecha_clase'] > $caducidad_final) {
//no se puede reservar por la caducidad
}

if($dia['fecha_clase'] > $limite_reserva) {
//No se puede reservar con más antelación de 2 días
}
    
answered by 04.09.2018 / 18:02
source
1

Simply why not use DateTime

$fecha_hora_reserva = '2018-09-06 14:47:56';

// Fecha actual
$now = new DateTime('NOW'); // Fecha hora actual

// Si es domingo incrementamos la fecha actual en 1 dia
if($now->format('N') == 7) {
    $now->modify('+1 day'); // Sumas un dia
    $now->setTime(7, 0, 0); // Estableces hora a las 7am
}

// Fecha de la reserva
$reserva = new DateTime($fecha_hora_reserva);

// Diferencia
$diff = $now->diff($reserva); // obtienes la diferencia

// calculamos los minutos para ajustar la precisión
$diff_minute = $diff->format('%i'); // minutos
$diff_minute += $diff->format('%h')*60;  // horas
$diff_minute += $diff->format('%a')*1440; // dias

// comprobamos el rango de horas
if(2880 >= $diff_minute) {
    echo 'menor o igual a 2 días(48h)';
} else { 
    echo 'mayor a 2 días(48h)';
} 
    
answered by 02.09.2018 в 14:41