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 2005 Forums
 Transact-SQL (2005)
 Date comparsion ?

Author  Topic 

mapperkids
Yak Posting Veteran

50 Posts

Posted - 2007-05-23 : 22:16:40
Hi,

FieldA contain a string '05/23/2007' and I tried the following in the filter for comparsion and select the FieldA equal to current date

Convert(Datetime, FieldA, 101) = GetDate()

It doesn't give me error, just no record returned.

Am I do something wrong on that statement?

Thanks!


khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-05-23 : 22:18:17
What is the datatype for FeildA ? datetime or string ?


KH

Go to Top of Page

mapperkids
Yak Posting Veteran

50 Posts

Posted - 2007-05-23 : 22:33:53
The fieldA defined as nChar(12) string
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-05-23 : 22:39:10
any particular reason why you are not using datetime to store a date ?

you can either use
convert(datetime, FieldA, 101) = dateadd(day, datediff(day, 0, getdate()), 0)

Or
FieldA = convert(varchar(10), getdate(), 101) 

Note : getdate() will return current date & time. The dateadd, datediff combination will set the time to 00:00:00

You should use datetime data type for your FieldA if possible.



KH

Go to Top of Page
   

- Advertisement -