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

Get Previous Month From Parameter??

Status
Not open for further replies.

sconti11

Technical User
Jan 31, 2011
95
US
I need to be able to get the previous month of a parameter.

Here is the code:

MONTH(dateCreated) = @Month

I tried MONTH(dateCreated) = @Month -1

But that does not work.....I thought it would since it works with the @Year prompt.

Any suggestions would be welcome!
 
You can try playing with this Where clause I use.

Code:
Where TrackingDate Between Convert(DATETIME, @DateParam1, 102) -- Date format (2010-05-24 00:00:00.000) AND DateAdd(dd,1,DateAdd(s, -1, Convert(DATETIME, @DateParam2, 102))) -- (2010-05-28 23:59:59.000)


and here is another example I like to use as a reference.

Code:
Select
DATEADD(dd, 0, DATEADD(mm, DATEDIFF(mm, 0, CURRENT_TIMESTAMP), 0)),  -- First Day of Month
DATEADD(ss,-1,DATEADD(dd, DATEDIFF(dd, 0, CURRENT_TIMESTAMP), 1))    -- End of Current Day

Hope this helps.

Thanks

John Fuhrman
 
It works now....not sure why it didn't before, but my original code is working.

Nonetheless, the suggestions in this thread are VERY helpful!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top