query using date field on sql server

B

bindurajeesh

why is it that when I put this code in the where clause

where begin_datetime =convert(varchar(10),dateadd("d",1,GETDATE()), 101)

no records are discovered but when I put

where begin_datetime >=convert(varchar(10),dateadd("d",1,GETDATE()), 101)

records for tomorrow and beyond are shown. I have also tried
begin_datetime=dateadd("d",1,getdate()) without conversion with same result
and I get the same results if I put conversion within the dateadd function.
I want records that have next day as begin_datetime and nothing more. Thanks.
 
C

Cinzia

bindurajeesh said:
why is it that when I put this code in the where clause

where begin_datetime =convert(varchar(10),dateadd("d",1,GETDATE()), 101)

no records are discovered but when I put

where begin_datetime >=convert(varchar(10),dateadd("d",1,GETDATE()), 101)

records for tomorrow and beyond are shown. I have also tried
begin_datetime=dateadd("d",1,getdate()) without conversion with same result
and I get the same results if I put conversion within the dateadd function.
I want records that have next day as begin_datetime and nothing more.
Thanks.

Hi bindurajeesh,
try this
where Convert(varchar(10), begin_datetime,101)
=convert(varchar(10),dateadd("d",1,GETDATE()), 101)
Bye
 
B

bindurajeesh

Thanks for quick response. I used between getdate() and getdate() + 1 and
that did the trick.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top