Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

datediff function problem 1

Status
Not open for further replies.

tanyasharma

Programmer
Apr 29, 2002
21
0
0
US
Hi I want to select customers from a table present in 3 month's before the today's date for that I am using datediff function as follows -
DATEDIFF(mm,getdate(),-3)...which is giving me absurd results. Can anybody else suggest me how to deal with this problem..it's urgent...
 
Datediff is used to calculate the difference between two dates. You are asking it to calculate the difference in months between today's date and -3. -3 would be 1899-12-29. The difference should be -1229 months.

You probably want to use the dateadd function which will add a value to a date. For example, the following will add -3 months to the current system date and return the resulting date as 2002-02-14.

dateadd(mm,-3,getdate()) Terry L. Broadbent - DBA
Computing Links:
faq183-874 contains "Suggestions for Getting Quick and Appropriate Answers" to your questions.
 
I've checked the books online on the DATEDIFF function and it pointed me to the DATEADD function. Could you write the query with a string like :

"select * table where table.date >= (DATEADD(mm,3,getdate()))"

?
 
SusieGirl,

Yes. The query you posted wil select all rows where the date >= than 3 months in the future. Terry L. Broadbent - DBA
Computing Links:
faq183-874 contains "Suggestions for Getting Quick and Appropriate Answers" to your questions.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top