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

dateadd

Status
Not open for further replies.

cathiec

Programmer
Oct 21, 2003
139
IE
select year(DATEADD(m,-1,(month(@intMonth)+year(@intYear))))


select year(DATEADD(m,-1,(month(1)+year(2006))))

i am using the above dateadd funtion. i use two variables in my query intMonth and intYear.

I want to use the dateadd function to return the year based on the month and year passed in as parameters.

basically if the year is 2006 and the month is jan (01) i want the year to be 2005 as the function should take one month away from the month and yeat thus giving 12/2005. i just need to be able to say that if the month is jan and the year is 2006 then the year returned from this query should be 2005. before jan 2006 is dec (2005). i have to use the two variables intMonth and intYear but i cant figure out how to pass these to the dateadd function and get the right year back,

the select statement above returns 1905 - taking one from the month and 100 from the year

would really appreciate any help with this one!
thanks.
 
Why not simply something like this ?
select year(DATEADD(m,-1,@youractualdate))

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top