You can implement this functionality as follows:
Structure of the database
For your database table structure, you can create something like this:
[ID - COD_EMRPESA - DIA_SEMANA - HORA_ABERTURA - HORA_FECHAMENTO]
Thus, the example company in the question would have 11 records in the database: 2 for each day from Monday to Friday and 1 for Saturday.
I do not think it is necessary to determine the period. What would be the period of a company that is open direct from 09:00 until 18:00 for example?
Storing the information in the bank
Based on the documentation of the date function() (http://php.net/manual/en/function.date.php), you would store the information of each company in the database as follows:
- the days of the week (DIA_SEMANA) from 1 to 7 (being 1 Monday and 7 Sunday).
- opening/closing times (HORA_ABERTURA and HORA_FECHAMENTO) as HH:MM (for example 14:03 or 17:10).
Checking opening and closing times
First, to get the day of the current week write:
$dia_da_semana = date('N')
And to get the current time and minute:
$horario = date('H:i')
Then, just compare the strings returned above with the values present in the database to determine whether or not the company is open.
What would be your doubt?
– Antony Alkmim
I’m having trouble coming up with the part where the opening and closing hours of the establishment will be, I create something [ID - COD_EMPRESA - DIA_SEMANA - HORA_ABERTURA - HORA_FECHAMENTO ]?
– LeoRS
I think it would be better this way...
[ID - COD_EMPRESA - DIA_SEMANA - HORA_ABERTURA_MANHA - HORA_FECHAMENTO_MANHA - HORA_ABERTURA_TARDE - HORA_FECHAMENTO_TARDE ]
... Because you have 2 schedules for each day of the week... Or you can do the way you said, just create another column, for example,[Periodo]
and define it as morning(1) or afternoon(2), so you can differentiate the 2 times on the same day of the week...– Daniel Ribeiro
Good, I will implement something like this, since some places have different hours (work late and night) [ ID - COD_EMPRESA - DIA_SEMANA - HORA_ABERTURA - HORA_FECHAMENTO - PERIODO ]
– LeoRS
I ask? are many registers (establishments) to include a timetable?
– chambelix