Solved

Using Between to select a date range does not retrieve inclusive dates.

Posted on 2006-07-16
3
5,861 Views
Last Modified: 2012-10-02
Hi there

I always thought that “BETWEEN”  Select * from table where SEARCH_DATE between '2005-12-01' AND '2005-12-31');
would select rows from say "2005-12-01 00:00:00" to "2005-12-31 23:59:59", seems like MYSQL does not.

I have a table. . .

ID|Search_Date_Time
3878879|2005-12-01 00:00:14
3878880|2005-12-01 00:00:15
. . .
3900061|2005-12-31 23:59:58
3900062|2005-12-31 23:59:58

When I do a select

SELECT ID, SEARCH_DATE_Time
FROM table1
WHERE
SEARCH_DATE between '2005-12-01' AND '2005-12-31');

. . .I only get rows up until '2005-12-30 23:59:59'

If I do
SELECT ID, SEARCH_DATE_Time
FROM table1
WHERE
SEARCH_DATE between '2005-12-01' AND '2005-12-31 23:59:59');

I do get the exact result

Is this to be expected?

How can I format the input date to search up to 23:59:59?

kind regards,
0
Comment
Question by:vandersk
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 19

Expert Comment

by:Kim Ryan
ID: 17119777
BETWEEN is the same as saying x >= min_val and x <= max_val

I think that specifyig only '2005-12-31'. mysql will assume a time value of 0:00:00

Alternatively, You could say this
SEARCH_DATE between '2005-12-01' AND '2006-01-01');
0
 
LVL 35

Accepted Solution

by:
Raynard7 earned 250 total points
ID: 17120237
You should also be able to do date(SEARCH_DATE) between '2005-12-01' AND '2005-12-31'

As date converts all datestimes to dates ie  to 0:00:00
0
 
LVL 35

Expert Comment

by:Raynard7
ID: 17452578
I do not understand why this answer merits a C - if you required more information - why didnt you ask for it?
0

Featured Post

How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Creating and Managing Databases with phpMyAdmin in cPanel.
This article shows the steps required to install WordPress on Azure. Web Apps, Mobile Apps, API Apps, or Functions, in Azure all these run in an App Service plan. WordPress is no exception and requires an App Service Plan and Database to install
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question