Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to calculate a running 12 month date range from previous month

0 views
Skip to first unread message

Jim in Spokane

unread,
Nov 3, 2009, 12:31:01 PM11/3/09
to
I want to skip the current month and start a 12 month date range from
previous month. If the current month is Nov 2009, the report would show data
from Nov 2008 to Oct 2009. I am getting mixed results, in the morning the
data shows Oct 2008 to Oct 2009, in the afternoon the data shows Nov 2008 to
Oct 2009 correctly.

This is what I am using now.
create date:
> GETDATE() - 365 - DAY(GETDATE())
<= DATEADD(ms, - 3, DATEADD(mm, DATEDIFF(mm, 0, GETDATE()), 0))

Thanks in advance for any help.
Jim

Uri Dimant

unread,
Nov 4, 2009, 2:33:32 AM11/4/09
to
Jim
SELECT <columns> FROM tb
WHERE dt>= DATEADD(month,DATEDIFF(month,0,GETDATE())-12,0) AND
dt<=DATEADD(month,DATEDIFF(month,0,GETDATE()),0)-1

"Jim in Spokane" <JiminS...@discussions.microsoft.com> wrote in message
news:F520A340-E28B-43EA...@microsoft.com...

Jim in Spokane

unread,
Nov 10, 2009, 12:24:01 PM11/10/09
to
Thanks! That worked great!

"Uri Dimant" wrote:

> .
>

0 new messages