SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 compare with the current date
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

kt
Yak Posting Veteran

80 Posts

Posted - 09/25/2013 :  12:00:17  Show Profile  Reply with Quote
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)

USA
7020 Posts

Posted - 09/25/2013 :  12:34:44  Show Profile  Reply with Quote
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

80 Posts

Posted - 09/25/2013 :  14:58:27  Show Profile  Reply with Quote
thank you
Go to Top of Page

madhivanan
Premature Yak Congratulator

India
22754 Posts

Posted - 09/26/2013 :  07:27:26  Show Profile  Send madhivanan a Yahoo! Message  Reply with Quote
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
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000