Page 1 of 1

How to calculate date one year prior to an input date

Posted: Thu May 26, 2011 1:28 pm
by Marley777
Thanks for reading.

If I have an input date and want to know the date one year prior using the input date as my starting point.

Trying to use DateFromDaysSince but need help with the syntax. Can someone please provide and example? Will it handle leap year?

Thanks.

Posted: Thu May 26, 2011 4:54 pm
by ray.wurlod
Don't you have an F1 button (help) on your keyboard? Can't you access IBM Information Center? Don't you have any manuals?

Posted: Thu May 26, 2011 11:43 pm
by peddakkagari
Write a stage variable like
if the monthfromdate(your_date)>2 and yearfromdate(your_Date)/4=0 then do -366 using DateFromDaysSince
else
-365 days

please inform us if you get any other solution

Posted: Fri May 27, 2011 12:35 am
by ray.wurlod
Convert the date to a string. Subtract 1 from the year. Subtract 1 from the day if the date is 02-29. Convert the string into a date. Make sure that the year is not 0001, which requires special handling.

Posted: Fri May 27, 2011 7:05 am
by Marley777
Thanks Ray...that works.