I have 4 buttons:
I want to activate 3 buttons from 9:00am to 6:00pm. I want to activate 1 button from 6:00pm to 9:00am.
This is the code I have so far:
<?php
$hora = new DateTime("now", new DateTimeZone('America/Mexico_City'));
$hora_actual = date_format($hora, 'G:ia');
$hora_limite = "6:00pm";
echo '<br><br>Hora completa: ' . $hora_actual ;
if($hora_actual == $hora_limite){
?>
<br><br>
<button>opcion 1</button>
<button>opcion 2</button>
<button>opcion 3</button>
<?php
}else{
?>
<br><br>
<button>opcion 0</button>
<?php
}
?>
you can do it like this:
since you only require the time with
and you use
G
that returns the time in format0 - 23
, theminutos
or if it isam
orpm
so it would be like thisexample:
You were close but no
You want that when
$hora_actual
it is higher , only>
one$hora_limite
button comes out and when it is lower, three come out. You can't do that with==
because that will only happen at 18:00:00, then the three buttons will return. That's why I changed the==
to the>
.All the best.