Solved

check date plus 90 days

Posted on 2007-11-26
2
1,394 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 250 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 250 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How do i Copy All the Tables from One Database to Another in SQL Server? 7 48
How to use TOP 1 in a T-SQL sub-query? 14 48
SQL Error - Query 6 42
What is this datetime? 1 20
This article will describe one method to parse a delimited string into a table of data.   Why would I do that you ask?  Let's say that you need to pass multiple parameters into a stored procedure to search for.  For our sake, we'll say that we wa…
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

828 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