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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

using DATEPART function in a SQL where statement 1

Status
Not open for further replies.

jerrylj

Programmer
Jun 17, 2002
6
US
I am using the following in a where statement for a sub-select: glpastyr.calmonth = DATEPART(month,getdate())-3

this will work fine if the current date is greater than march 31 of any given year. If it is less than 3/31/xxxx then an error is returned because the month becomes a negative number.

Do any of you know of a way around this?
 
Can you use the DateAdd function?

In SQL Server it would be:

WHERE glpastyr.calmonth = Month(DateAdd(month,-3,getdate())


~Brian
 
Thanks it looks like that will work. One of the problems with being self tought is not knowing all of the functions.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top