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

Posted on 2006-07-16
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. . .

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

FROM table1
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
FROM table1
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,
Question by:vandersk
  • 2
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');
LVL 35

Accepted Solution

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
LVL 35

Expert Comment

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

Featured Post

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
MySQL - Limit or Top Records 15 49
MySQL left join performance 4 38
join tables 4 55
I've got an interview this morning and I want to sound intelligent... 4 53
A lot of articles have been written on splitting mysqldump and grabbing the required tables. A long while back, when Shlomi ( had suggested a “sed” way, I actually shell …
Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

777 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