sql - Setting date end parameter to 12 months ago -
i have pull comparative data , want set reoport run automatically.
to first date range use parameters
=dateadd("m", -3, dateserial(year(now()), month(now()), 1))
this start date 3 months ago i.e. 1 jan 2013.
=dateadd("d", -1, dateserial(year(now()), month(now()), 1))
this end date, last day of last month 31 mar 2013.
i need same dates last year using
=dateadd("m", -15, dateserial(year(now()), month(now()), 1))
this start date 15 months ago ie. 1 jan 2012
what use find last day of month 13 months ago, i.e. 31 mar 2012?
since you've worked out 31-mar-2013, subtract year using nested dateadd
functions:
=dateadd("yyyy" , -1 , dateadd("d", -1, dateserial(year(now()), month(now()), 1)))
this returns 31-mar-2012.