Error:SQL “between” not inclusive

+1 vote

I have a query like this:

SELECT * FROM Cases WHERE created_at BETWEEN '2020-05-01' AND '2020-05-08'

But this gives no results even though there is data on the 1st.

created_at looks like 2020-05-01 13:15:9, I suspect it has to do with the time? How could this be resolved?

It works just fine if I do larger date ranges, but it should (inclusive) work with a single date too.

May 28 in Java-Script by kartik
• 30,630 points
76 views

1 answer to this question.

0 votes

Hello,

It is inclusive. You are comparing datetimes to dates. The second date is interpreted as midnight when the day starts.

One way to fix this is:

SELECT *
FROM Cases
WHERE cast(created_at as date) BETWEEN '2020-05-01' AND '2013-05-08'

Another way to fix it is with explicit binary comparisons

SELECT *
FROM Cases
WHERE created_at >= '2020-05-01' AND created_at < '2020-05-08'

Hope this works!!

answered May 28 by Niroj
• 66,420 points

Related Questions In Java-Script

0 votes
1 answer

How to trigger jquery.ajax() error callback based on server response, not HTTP 500?

Hello @kartik, The error callback will be executed ...READ MORE

answered Jun 18 in Java-Script by Niroj
• 66,420 points
1,780 views
0 votes
1 answer

Error:Request header field X-Requested-With is not allowed by Access-Control-Allow-Headers

Hello @kartik, Access-Control-Allow-Headers does not allow * as accepted value. Instead of ...READ MORE

answered Jul 6 in Java-Script by Niroj
• 66,420 points
175 views
0 votes
1 answer

Error :jquery's .ajax() method not sending my session cookie

Hello @kartik, AJAX calls only send Cookies if ...READ MORE

answered Aug 25 in Java-Script by Niroj
• 66,420 points
50 views
0 votes
1 answer

Error: listen EADDRINUSE while using nodejs?

Hello kartik, Two possible solutions for this: Free currently ...READ MORE

answered Apr 24 in Java-Script by Niroj
• 66,420 points
276 views
+1 vote
1 answer

How to make anchor tag with routing using Laravel?

Hey @kartik, First you have to go to ...READ MORE

answered Mar 18 in Laravel by Niroj
• 66,420 points
2,715 views
0 votes
1 answer

What is redirection in Laravel?

Named route is used to give specific ...READ MORE

answered Mar 18 in Laravel by Niroj
• 66,420 points
329 views
0 votes
1 answer

How to install Laravel via composer?

Hello, This is simple you just need to ...READ MORE

answered Mar 23 in Laravel by Niroj
• 66,420 points
221 views
+1 vote
1 answer

What are named routes in Laravel and How can specify route names for controller actions?

Hey @kartik, Named routing is another amazing feature of ...READ MORE

answered Mar 23 in Laravel by Niroj
• 66,420 points
3,364 views
0 votes
1 answer

Error:Invariant Violation: _registerComponent(…): Target container is not a DOM element

Hii @kartik, Basically what you done is right, ...READ MORE

answered Jun 8 in Java-Script by Niroj
• 66,420 points
473 views
0 votes
1 answer

Error:Origin is not allowed by Access-Control-Allow-Origin

Hello @kartik, The easiest way to handle this ...READ MORE

answered Jun 17 in Java-Script by Niroj
• 66,420 points
166 views