How to display text at a certain mysql time

Asked

Viewed 45 times

-1

Good evening, my compliments,

I have a php system with mysql, could someone help me with my question? My site displays data from companies in frontend. The open and closed time data are in the database. However, I would like to display a text on the site when it is at such a time for example. 08h "OPEN" and 18h "CLOSED" according to the time saved in the bank

Grateful.

  • makes a if in the code php to check the time and show the correct message

  • Is it just the schedule? It’s every day of the week?

2 answers

1

Hello, You could do by consulting the BD data something like the example below:

<?php

// consulte esses dados do BD
$dataAberto = "2020-10-23 08:00:00";
$dataFechado = "2020-10-23 18:00:00";

// data atual
$dataAtual = date("Y-m-d H:i:s");

if($dataAtual >= $dataAberto AND $dataAtual <= $dataFechado){
    echo "Aberto";
}else{
    echo "Fechado";
}

0

As Ricardo said, you do an if in php for this. If the times are already predefined, you do not need to use the BD, can do with Javascript, vc will compare the current time, when the person is accessing the site, with the pre-set time. This link can give you a light on that. Compare two dates and times

Browser other questions tagged

You are not signed in. Login or sign up in order to post.