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 2000 Forums
 Transact-SQL (2000)
 Show records between present date and blank number of days in the future?

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2004-06-07 : 12:10:19
Kenyell writes "Hello team. I only hope that you can answer my question as is one that has not been answered in days. Here is my dilema.

I am trying to query using dates. I need it to give me all the records from the present date up to 14 days in the future. Such as all the customers that need to be contacted in the next 14 days based on today's date. Any information you can give me will be greatly appreciated. I have posted on other forums and tried the replies to no avail. I hope you can help me. Thanks in advance."

JimL
SQL Slinging Yak Ranger

1537 Posts

Posted - 2004-06-07 : 12:46:16
I think your looking for something like this.


SELECT Customers
from Table1
Where Conatctdate Between Getdate() And DATEADD(day, 14, Getdate())


Jim
Users <> Logic
Go to Top of Page

gpl
Posting Yak Master

195 Posts

Posted - 2004-06-07 : 12:48:13
Kenyell
Try this
Select * from MyTable
Where SomeDate Between Convert(Datetime, Convert(Char(10), GetDate(), 103), 103) AND Convert(Datetime, Convert(Char(10), DATEADD(dd , 15, GetDate()), 103), 103)

What this does is simply check for rows between 2 dates
Now dates also hold a time component, so the 2 convert functions first turns the current date to a string, with no time (eg 22/04/2004) then converts it back to a date (actually, with a time of midnight - 00:00:00).
The second set of convert functions adds 15 days to today and does the same conversion (that is, returns the date and time of midnight of the 14/15th day in the future)

Edit - Jims code is essentially the same, but wouldnt show any rows that came up for this morning (as it is now afternoon)

Graham
Go to Top of Page

kenyell
Starting Member

1 Post

Posted - 2004-06-07 : 17:12:30
Thanks guys, you people are real life-savers. The suggestions work perfectly.
Go to Top of Page
   

- Advertisement -