Klipp Ohei
Klipp Ohei

Reputation: 385

MYSQL: Inserting time period OR time/moment

I want to build a little calendar system for my website.

When the user creates an appointment he can choose between a time period (like 3rd march to 7th march) and a concrete day with time/moment (like 3rd march 2016 11:00).

I want to insert this into the mysql database.

Values for inserting a time period:

date1: 3rd march 2016

date2: 7th march 2016

Values for inserting a concrete day with time:

datetime: 3rd march 2016 11:00

Now the question I stuck on: How should the table look like?

I thought on sth like this (only the columns): id | appointment | date1 | date2 | datetime1

And when the user inserts a time period the datetime-field would be empty. But is this the way to go?

Upvotes: 0

Views: 89

Answers (1)

juergen d
juergen d

Reputation: 204766

One way would be

id
appointment
startdate
starttime (empty if it is an entry for a whole day)
enddate (empty if it is a single entry without a period)
endtime (empty if it is an entry for a whole day)

Upvotes: 1

Related Questions