Solved

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

Posted on 2006-07-16
3
5,659 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
  • 2
3 Comments
 
LVL 19

Expert Comment

by:Kim Ryan
Comment Utility
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
Comment Utility
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
Comment Utility
I do not understand why this answer merits a C - if you required more information - why didnt you ask for it?
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Foreword In the years since this article was written, numerous hacking attacks have targeted password-protected web sites.  The storage of client passwords has become a subject of much discussion, some of it useful and some of it misguided.  Of cou…
Introduction In this article, I will by showing a nice little trick for MySQL similar to that of my previous EE Article for SQLite (http://www.sqlite.org/), A SQLite Tidbit: Quick Numbers Table Generation (http://www.experts-exchange.com/A_3570.htm…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

772 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now