How to handle calendar in the database

0

Hello,

I'm doing a personal project, to practice programming and I came across a situation that I'm having trouble solving. A user has a routine that is repeated weekly, where each day of the week he has different free time, for example:

Monday he has from 5 p.m. to 8 p.m. free, Tuesday is from 8 p.m. to 2 p.m., and so goes until Sunday, but next Monday he has the same free time, from 5 p.m. to 8 p.m. free. >

What is the best way to save these free time in a MySQL database. In order to be efficient and take up as little space as possible?

    
asked by anonymous 12.08.2017 / 13:45

1 answer

0

Table: Freetime

id*   |usuario_id  |  dow   |   hora_inicial   |   hora_final
 1         1           2             17                20
 2         1           3             08                14

where, usuario_id is fk for usuarios table, and dow is the 'day of week' ie weekday, being sunday = 1, and saturday = 7.

see more about the mysql function, DayOfWeek() : link

    
12.08.2017 / 15:02