?
Solved

check date plus 90 days

Posted on 2007-11-26
2
Medium Priority
?
1,501 Views
Last Modified: 2008-02-01
I have a query where I need to check if the date stored in the database is still active.  The formula to determine if the date is still active is if the if the Contract_End_c field is not past todays date plus 90 days.

The date stored in the database is in the format: mm/dd/yyyy

This is what I was trying:

Select a.AccountNumber, a.Contract_End__c from Account a WHERE a.AccountNumber = '123456' AND a.Contract_End_c <= DATEADD(dd, 90, getdate())

Thanks for any help.
0
Comment
Question by:-Dman100-
2 Comments
 
LVL 18

Accepted Solution

by:
JR2003 earned 1000 total points
ID: 20351495
The date is stored in a text column?
You will need to convert it to a date

AND Cast(Right(Contract_End_c,4) + '-' + Left(Contract_End_c, 2) + '-' + SUBSTRING(Contract_End_c,4 , 2) as datetime)  <= DATEADD(dd, 90, getdate())

0
 
LVL 18

Assisted Solution

by:Yveau
Yveau earned 1000 total points
ID: 20351743
... or (as it is stored as a string):

Hope this helps ...

Select  a.AccountNumber
,       a.Contract_End__c 
from    Account a 
WHERE   a.AccountNumber = '123456' 
AND     convert(datetime, a.Contract_End_c, 101) <= DATEADD(dd, 90, getdate())

Open in new window

0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: When running hybrid database environments, you often need to query some data from a remote db of any type, while being connected to your MS SQL Server database. Problems start when you try to combine that with some "user input" pass…
In SQL Server, when rows are selected from a table, does it retrieve data in the order in which it is inserted?  Many believe this is the case. Let us try to examine for ourselves with an example. To get started, use the following script, wh…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question