开发者

PHP/MySQL - Calender/Setting appointments question

开发者 https://www.devze.com 2023-03-20 02:04 出处:网络
I have to columns, both datetimes. One\'s for the time the appointment starts and the other is for when the appointment ends.

I have to columns, both datetimes. One's for the time the appointment starts and the other is for when the appointment ends.

I need a 开发者_JAVA技巧mysql query that'll basically return available time during the day so I can set appointments without them overlapping.

So if I'm open on Monday from 1pm to 6pm and have an appointment from 2pm to 3pm it'll return two results:

DATE 13:00:00 - DATE 14:00:00 and DATE 15:00:00 - DATE 18:00:00


My solution would be to always have 2 datetimes, one being the start time, one being the end time. That would be the 'cleaner' way in my opinion.

The way to get the open appointments is something like this:

SELECT *
FROM appointments
WHERE end_time = "0000-00-00 00:00:00" (or > in stead of = for all appointments)

Or if you leave it empty something like this:

SELECT *
FROM appointments
WHERE end_time IS NULL (or IS NOT NULL for all appointments)
0

精彩评论

暂无评论...
验证码 换一张
取 消