Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Getting data within a date range gives wrong results

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2004-07-08 : 11:58:56
Imtiaz writes "OK this problem has had me confused for two days now. And I can't take it any more. Here is the problem

This is how my query looks like:

select field1,field2,datefield1
from view1
where datefield1 between '06/01/2004' and '06/27/2004'
order by datefield1 desc

The results don't show anything exisiting on the 06/27/2004 date.

Whereas when i run this query:

select field1,field2,datefield1
from view1
order by datefield1 desc

It shows me 4 records which have datefield1=06/27/2004

Any ideas wats going on??

I would really appreciate your help.

Thanking you,
Imtiaz"

Kristen
Test

22859 Posts

Posted - 2004-07-08 : 12:38:40
Use

where datefield1 >= '06/01/2004'
and datefield1 < '06/27/2004'

instead.

Note also that your date format is not "safe". SQL may interpret '01/02/2004' as dd/mm/yyyy or mm/dd/yyyy.

Kristen
Go to Top of Page

Arnold Fribble
Yak-finder General

1961 Posts

Posted - 2004-07-08 : 14:28:38
I think you meant


where datefield1 >= '06/01/2004'
and datefield1 < '06/28/2004'

Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2004-07-08 : 14:33:34
You're quite right Arnold, thanks. I was going to amke an excuse for the time over here, and the glass in my hand, but you're in the same boat!

Kristen
Go to Top of Page

imtiazmt
Starting Member

1 Post

Posted - 2004-07-10 : 04:38:12
thanks ppl.. this works
Go to Top of Page
   

- Advertisement -