0

I'm grouping data with dateadd() by weeks, but I want to group by months instead. I've got this fun little dateadd function.

   DATEADD(day, - (1 * DATEPART(dw, Orders.OrderDate - 1)) + 1, CONVERT (date, Orders.OrderDate, 103))

so we're subtracting a week off of the current date - it seemed to me as simple as just changing the datepart to month and subtracting 1 from it,however, this gives me some pretty wacky results how do I modify this to subtract months instead of weeks?

nbpeth
  • 2,967
  • 4
  • 24
  • 34
  • those best thing I've come up with is DATEADD(month, DATEDIFF(month, 0, Orders.OrderDate), 30) - but I'm not trusting the results I'm getting – nbpeth Dec 24 '13 at 17:17

1 Answers1

0

so you basically already tried:

DATEADD(day, - (1 * MONTH(dw, Orders.OrderDate - 1)) + 1, CONVERT (date, Orders.OrderDate, 103))

  • month only takes on parameter, month(date) as far as I can tell - so I did not try that yet – nbpeth Dec 25 '13 at 19:36