0

I'm looking for a way to get all entries from my reservations table to be shown in a calendar.

Now I know that I will have to iterate over all days of the current week and run a database query to select all reservations with dt_from >= start_of_the_week / start_of_the_day and dt_to <= end_of_the_week / end_of_the_day.

But that only gives me the reservations that start or end within the week / respectively within the given day.

What I am trying to figure out is: How do I get the reservations which started earlier and/or end after the current day or week?

I have some kind of the following table design

+----+-------------------+---------------------+---------------------+ | ID | NAME | DT_FROM | DT_TO | +----+-------------------+---------------------+---------------------+ | 1 | Jeff Atwood | 2020-01-06 09:00:00 | 2020-01-16 09:00:00 | | 2 | Terry Jones | 2020-01-30 09:00:00 | 2020-02-16 09:00:00 | | 3 | Brian of Nazareth | 2020-02-06 09:00:00 | 2020-03-16 09:00:00 | +----+-------------------+---------------------+---------------------+

I have been stuck with this for a while now and would appreciate a push into the right direction.

Thank you :)

2
  • 2
    If you need to check that two intervals overlaps you must check that each interval start is less then the end of another interval. I.e. (dt_from <= end_of_the_week / end_of_the_day) AND (dt_to >= start_of_the_week / start_of_the_day).
    – Akina
    Feb 5, 2020 at 13:56
  • You had given the table data sample. Please add your code to your question. Feb 7, 2020 at 11:23

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.