How to calculate date one year prior to an input date

Post questions here relative to DataStage Enterprise/PX Edition for such areas as Parallel job design, Parallel datasets, BuildOps, Wrappers, etc.

Moderators: chulett, rschirm, roy

Post Reply
Marley777
Premium Member
Premium Member
Posts: 316
Joined: Tue Jan 27, 2004 3:26 pm

How to calculate date one year prior to an input date

Post 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.
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post 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?
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
peddakkagari
Participant
Posts: 26
Joined: Thu Aug 12, 2010 12:07 am

Post 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
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post 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.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Marley777
Premium Member
Premium Member
Posts: 316
Joined: Tue Jan 27, 2004 3:26 pm

Post by Marley777 »

Thanks Ray...that works.
Post Reply