question

naveen 1 1 avatar image
naveen 1 1 asked

In Sql2005 Display records based on given from and to dates

Hi,

I need display records based on from and to dates in sql syntax

i tried like this select * from dbo.BuzzMaster where date BETWEEN '02/07/2010' and '02/09/2010'

output comes for the date 02/08/2010

But if i give like select * from dbo.BuzzMaster where date BETWEEN '02/07/2010' and '02/08/2010'

Im not able to get records on date 02/08/2010

So i tried select * from dbo.BuzzMaster where date >= '2/7/2010' and date <= '2/8/2010'

BUT then also

Im not able to get records on date 02/08/2010

Kindly help me guys

thanks in advance

Naveen...

sql-server-2005
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
Squirrel 1 avatar image
Squirrel 1 answered

It is obviously your the date column in the BuzzMaster contains time.

So when you use BETWEEN '02/07/2010' and '02/09/2010' you get the record.

When you specify BETWEEN '02/07/2010' and '02/08/2010' means greater than 2010 Feb 07 and less or equal to 2010 Feb 08 midnight. So the record with date 2010 Feb 08 will be excluded.

Note : between '02/07/2010' and '02/08/2010' is the same as date >= '2/7/2010' and date <= '2/8/2010'. So you will not get any record return

If you want select the record with date '02/08/2010' you should use >= and <

where date >= '20100208' -- greater than Feb 08 midnight and date < '20100209' -- less than Feb 09

The above will give you all records with date Feb 08

Note that i specify the date in ISO format (YYYYMMDD).

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.