php – Display div according to day and time

Question:

I'm putting together a (sort of emergency) system for the church, to broadcast live, because of social isolation. On the Page where I'm embedding the live, on the church's website, I want that, if the person enters within the official day and time of worship, and the video doesn't start, a div appears for him with a "click here" to restart on the page.

If it is other days and times, where there is not live, another div appears, with a "click here" to go to the recorded services page.

So, in summary, when the person enters, php will take the day and time, and check with the days and times of the variables. If you hit one, div 1 appears, if you don't, div 2 appears.

I have the idea, but I want to run while I can barely crawl, then it became difficult. Here's the code I thought about but didn't work:

<?php
$dataatual = ('w');
$horaatual = ('H:i:s');
$horade    = '19:59:59';
$horaate   = '21:00:01';
$horade1   = '08:59:59';
$horaate1  = '10:00:01';
$horade2   = '19:29:59';
$domingo   = '0';
$quarta    = '3';
$quinta    = '4';

if (($dataatual = $domingo and ($horaatual >= $horade1 and $horaatual <= $horaate1))) or (($dataatual = $domingo and ($horaatual >= $horade2 and $horaatual <= $horaate))) or (($dataatual = $quarta and $horaatual >= $horade and $horaatual <= $horaate))) or (($dataatual = $quinta and $horaatual >= $horade and $horaatual <= $horaate))) { ?>
<div class="conteudo">

<h3>Olá, estamos ao vivo. Caso não esteja visualizando o vídeo, Clique <a href="https://www.ibnagv.com.br/cultos-ao-vivo/">AQUI </a>para atualizar sua página.</h3>
  </div><?php } ?>

else { ?>

<div class="conteudo1">
<h3>Olá, no momento não estamos ao vivo. Mas você pode assistir nossos cultos gravados, clicando <a href="https://www.ibnagv.com.br/cultos-gravados/">AQUI </a>ou acessando o Menu Mídias / Cultos Gravados. Obrigado. </h3></div>

<?php } ?>

Answer:

There were two problems, the first was in the $currentdate and $currenttime variables that were without the date function, the second was in the IF that was being closed before the other conditionals, causing a syntax error.

I tweaked the code and it looked like this:

$dataatual = date('w'); $horaatual = date('H:i:s'); $horade = '19:59:59'; $horaate = '21:00:01'; $horade1 = '08:59:59'; $horaate1 = '10:00:01'; $horade2 = '19:29:59'; $domingo = '0'; $quarta = '3'; $quinta = '4'; if (($dataatual = $domingo and ($horaatual >= $horade1 and $horaatual <= $horaate1)) or (($dataatual = $domingo and ($horaatual >= $horade2 and $horaatual <= $horaate))) or (($dataatual = $quarta and $horaatual >= $horade and $horaatual <= $horaate)) or (($dataatual = $quinta and $horaatual >= $horade and $horaatual <= $horaate))){ echo '<div class="conteudo"> <h3>Olá, estamos ao vivo. Caso não esteja visualizando o vídeo, Clique <a href="https://www.ibnagv.com.br/cultos-ao-vivo/">AQUI </a>para atualizar sua página.</h3></div>'; } else { echo '<div class="conteudo1"> <h3>Olá, no momento não estamos ao vivo. Mas você pode assistir nossos cultos gravados, clicando <a href="https://www.ibnagv.com.br/cultos-gravados/">AQUI </a>ou acessando o Menu Mídias / Cultos Gravados. Obrigado. </h3></div>'; }

Scroll to Top