Skip to content
Advertisement

SQL Date Filter: Return results when start date = end date

:startDate and :endDate are given value from html input and passed as parameters with AJAX. I want to return notifications BETWEEN :startDate and :endDate, but also return a notification if startDate is equal to endDate.(A user enters the same date for both input boxes).

The OR statement breaks the first condition. The query works with just the BETWEEN statement. If a user inputs the same date value for startDate and endDate, I would expect the OR part of the query to return any notifications that have the same date value as was entered into both input boxes. Expected output would look like: startDate = 10/10/2020 endDate = 10/10/2020

returns any notifications with the date value 10/10/2020

Advertisement

Answer

You are saying:

The query works with just the BETWEEN statement.

and this is true, because BETWEEN has inclusive range meaning that

is the same as:

and that’s why there is no need by your OR condition:

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement