Fabio is actually wrong if hours, minutes, and seconds are included at this time.
where date >= '2013-06-01' and date <= '2013-06-06'
becomes internally
where date >= '2013-06-01 00:00:00' and date <= '2013-06-06 00:00:00'
So, you really just select 1 second from 2013-06-06, not all day!
Same thing BETWEEN, of course. To get all day 2013-06-06 you have to write
where date >= '2013-06-01' and date <= '2013-06-06 23:59:59'
or
where date BETWEEN '2013-06-01' AND '2013-06-06 23:59:59'
Go ahead, try it yourself (or see that it lives in sqlfiddle ):
create table foo (my_date date, my_timestamp timestamp, my_datetime datetime); insert into foo values ('2013-06-06', '2013-06-06 12:23:34', '2013-06-06 13:35:48'); select * from foo where my_date <= '2013-06-06'; select * from foo where my_timestamp <= '2013-06-06'; select * from foo where my_datetime <= '2013-06-06'; select * from foo where my_timestamp <= '2013-06-06 23:59:59'; select * from foo where my_datetime <= '2013-06-06 23:59:59';
source share