Record in the database the office hours and make an appointment

2
Hello, I'm looking for a North to create with PHP and MySQL a way to record in the database the hours of operation of several establishments, so that I can easily search and display if the establishment is open, or closed, or until what time there is expedient on that day.

Something like the example below I plan to do, just like Google Maps.

    
asked by anonymous 18.12.2014 / 14:43

1 answer

1

You can implement this functionality as follows:

Database structure

For the structure of your database table, you can create something like this:

[ID - COD_EMRPESA - DIA_SEMANA - HORA_ABERTURA - HORA_FECHAMENTO]

So, the example company in question would have 11 records in the database: 2 for each day Monday through Friday and 1 for Saturday.

I do not think it's necessary to determine the period. What would be the period of a company that stays open from 09:00 to 18:00 for example?

Storing the information in the bank

Based on the documentation for the date () function ( link ), you would store the information for each company in the database as follows:

  • the days of the week (DIA_SEMANA) from 1 to 7 (being 1 Monday and 7 Sunday).
  • the opening / closing times (HOUR_OPERTY and HOUR_CONTACT) as HH: MM (for example 14:03 or 17:10).

Checking opening and closing times

First, to get the current day of the week write:

$dia_da_semana = date('N')

And to get the current hour and minute:

$horario = date('H:i')

So, just compare the strings returned above with the values in the database to determine if the company is open or not.

    
18.12.2014 / 17:34