RustyHamster
RustyHamster

Reputation: 359

Sql Getdate on previous years stats

Im looking to report on Month to date(MTD) and previous years MTD My code for MTD is WHERE (Month(DateCompleted) = Month(getdate()) AND YEAR (DateCompleted) = YEAR (getdate ())) Is there a way i can look at last years exact month as this month

for for instance this query above gives me all sales for the month of june 2014 so far. I want to compare them in a dynamic report so i would like to view June 2013 . Cheers

Upvotes: 0

Views: 50

Answers (2)

lc.
lc.

Reputation: 116458

Just subtract 1:

where Month(DateCompleted) = Month(getdate())
and Year(DateCompleted) = Year(getdate()) - 1

Upvotes: 1

Jaaz Cole
Jaaz Cole

Reputation: 3180

It strikes me that simply decrementing the year would do this.

YEAR (DateCompleted) = YEAR (getdate ())-1

Upvotes: 1

Related Questions