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
• 16,330 points
30 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
• 33,770 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
• 33,770 points
44 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 3 days ago in Java-Script by Niroj
• 33,770 points
20 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
• 33,770 points
88 views
0 votes
1 answer

Error: Unexpected token import in nodejs

Hello, Unfortunately, Node.js doesn't support ES6's import yet. To accomplish what ...READ MORE

answered Apr 24 in Java-Script by Niroj
• 33,770 points
723 views
0 votes
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
• 33,770 points
888 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
• 33,770 points
86 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
• 33,770 points
101 views
0 votes
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
• 33,770 points
513 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
• 33,770 points
165 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
• 33,770 points
42 views