hardei
12th March 2007, 10:16
:confused:Hi Guys,
Need your help.I have developed one report where in input criteria i put month and year.i want to calculate the data for last 12 months from the date which i mentioned on the form.i need to take care of leap year also.

For eg.
If i mention month is 3 and year 2006 on the form then i need to calculate the data from march 2006 to april 2005

Can anybody help me in that?

Waiting or your reply guys..

mark_h
12th March 2007, 13:49
Simple - just build two different dates based off the 3/2006 input. So your start date would look like this

|Year is 2006 and month is 3
start.date = date.to.num(year-1,month+1,1)
end.date = date.ti.num(year, month+1,1)
end.date = end.date -1

So I see no reason why you need to worry about leap years I think this will work.

norwim
12th March 2007, 16:44
Hi there,

don't have a machine here to test what date.to.num(year,13,1) will return, but I'd suggest a different approach:
long testyear | to truncate when divided by 4
if month=12 then
enddate=date.to.num(year+1,1,1)-1
else
enddate=date.to.num(year,month+1,1)-1
endif
testyear=year/4
if testyear*4=year then
startdate=enddate-366
else
startdate=enddate-365
endif

hth

Norbert