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
 General SQL Server Forums
 New to SQL Server Programming
 compare with the current date

Author  Topic 

kt
Yak Posting Veteran

88 Posts

Posted - 2013-09-25 : 12:00:17
from my table:convert(varchar,Rec.expdate,101) as exp:
01/19/2038
08/12/2013
08/12/2013

I only want record is >= the current date but looks like my syntax is not working right because I got nothing return instead of 01/19/2038. An any one help?
Thanks
-----
and convert(varchar,Rec.expdate,101) >=convert(varchar,getdate(),101)

Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)

7020 Posts

Posted - 2013-09-25 : 12:34:44
You are converting the date to varchar format, "09/25/2013", so the compare is done as a varchar.

You should compare as a datetime value:
and  Rec.expdate >= convert(datetime,convert(date,getdate()))







CODO ERGO SUM
Go to Top of Page

kt
Yak Posting Veteran

88 Posts

Posted - 2013-09-25 : 14:58:27
thank you
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2013-09-26 : 07:27:26
Also read this http://beyondrelational.com/modules/2/blogs/70/posts/19678/understanding-datetime-columns-and-effecient-filtering-quick-references.aspx

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -