Juan Lopez
Juan Lopez

Reputation: 1

Looking at date range and find if the is available

I have a reservation from Sat, 01 Dec 2018 02:45:00 UTC +00:00 to Sun, 02 Dec 2018 02:45:00 UTC +00:00 but I want to search availability from Sat, 01 Dec 2018 05:15:00 UTC +00:00 to Sat, 01 Dec 2018 06:45:00 UTC +00:00 this is within the previous reservation obviously this reservation is impossible because its already book.

unfortunately, when I query this comes as available because it does not touch any date of the reserved date.

how can I query this returning the current reservation?

I am using rails 5 Postgres Database.

reserved Initial date |-------------------------| reserved final date
      search Initial Date|-----------|search final Date

Upvotes: 0

Views: 36

Answers (1)

Kaushik Nayak
Kaushik Nayak

Reputation: 31656

You can use the OVERLAPS operator

..WHERE (availability_start, availability_end) 
          OVERLAPS (reservation_from, reservation_to) IS FALSE

Date/Time Functions and Operators

Upvotes: 1

Related Questions