Add/substract months from 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
sachinamr
Participant
Posts: 2
Joined: Thu Jul 07, 2005 4:32 am

Add/substract months from date

Post by sachinamr »

I want to substract 3 moths from date field. I would appreciate if anyone tells me how do it.

Thanks in advance.
cmmurari
Participant
Posts: 34
Joined: Sun Jan 02, 2005 9:55 am
Location: Singapore

Post by cmmurari »

pls refer date function's in Parallel Job developer's guid page 1105
you can try DateFromDaysSince

regards,
krish
kumar_s
Charter Member
Charter Member
Posts: 5245
Joined: Thu Jun 16, 2005 11:00 pm

Post by kumar_s »

Hi,
When ever you forcast or go beyond the given date, make sure you handle leap year as well.

regards
kumar
srikanthd1978
Charter Member
Charter Member
Posts: 38
Joined: Wed Mar 17, 2004 1:16 am
Location: USA

Post by srikanthd1978 »

Using the followiing

example:

OutPutDate = DateFromDaysSince(-90, Link.InputDate)..

but there needs to be more rigor wrapped around for the Month of Feb, as well as Leap Year calculation...

..another sure shot method is ..if u can extract this data from a DB, using a User Defined Query ( like using a TimestampDiff function or a dateDiff function on the DB side ), that way u can avoid using complex Xfm( using stage Variables) to take Leap Year and the Month of Feb into Consideration...
als110
Participant
Posts: 43
Joined: Fri Nov 05, 2004 11:21 am
Location: United States

Post by als110 »

I handled it by converting the date into a julian day added or subtracted the 3 months (-90) then converting it back to the date format:

DateFromJulianDay((JulianDayFromDate(lnkStmOut.POL_SYS_KEY_DT) - 180))
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Of course, 3 months can be anywhere between 90 and 92 days. Other variations are possible if you're dealing with the years when "they" fiddled with the calendar. A more robust solution would manipulate the month number and, as a possible consequence, the year and day numbers.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Post Reply