Date Coverting into 2 months Back

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
sandeepJajee
Participant
Posts: 12
Joined: Sat Jun 27, 2009 5:44 am

Date Coverting into 2 months Back

Post by sandeepJajee »

Hi,

I have 1 requirment in Parallel Jobs regarding date conversion.
Input Date is Parametreized as #Ws_Mig_Date#.The output date should be #Ws_Mig_Date# - 2 months.

Ex1:#Ws_Mig_Date#= 2010-04-30
Output Date=2010-02-28

Ex2::#Ws_Mig_Date#= 2011-05-25
Output Date=2011-03-25

as you see here in Ex1 when we do 2 months back its 30 feb and is not valid date so we need to make sure its valid date.
We need to consider the leap year logic as well.
i tried using date functions in parallel..but it would be complicated to implement.
so if any one has routines used or any other logic ..it would be appreciated.

Thanks
Sandeep
Regards,
Sandeep Jajee
ArndW
Participant
Posts: 16318
Joined: Tue Nov 16, 2004 9:08 am
Location: Germany
Contact:

Post by ArndW »

What is your definition of "2 months". If it is "60 days" then you could convert your date to day-of-year, subtract 60, then convert back to a date (checking for negative numbers on the way).
If you define 2 months as "same day number 2 months back" then you need to add extra rules for subtracting 2 months from dates such as "April 30" but the approach is still similar - convert the date into 3 components, year, month and day and then perform the conversion math in distinct steps, i.e. through stage variables.
sandeepJajee
Participant
Posts: 12
Joined: Sat Jun 27, 2009 5:44 am

Post by sandeepJajee »

Hi andrew,

My Definition of 2 months means,subtract 2 months from give date and if the date after difference is correct for the month keep it else take the correct date for the particular month.

Ex date=30-04-2010 - 2months output= 30-02-2010 but 30-02-2010 is not valid date for the given year 2010.so we need to keep 28th feb as correct date .if it is valid date after differnce then the keep it.
output=28-02-2010

I am looking for any routine to get this value.i tried other date functions in Parallel jobs but it would be complicated to implement ?

any help would be appreciated..

Thanks in advance.

Sandeep
Regards,
Sandeep Jajee
sandeepJajee
Participant
Posts: 12
Joined: Sat Jun 27, 2009 5:44 am

Post by sandeepJajee »

Hi andrew,

My Definition of 2 months means,subtract 2 months from give date and if the date after difference is correct for the month keep it else take the correct date for the particular month.

Ex date=30-04-2010 - 2months output= 30-02-2010 but 30-02-2010 is not valid date for the given year 2010.so we need to keep 28th feb as correct date .if it is valid date after differnce then the keep it.
output=28-02-2010

I am looking for any routine to get this value.i tried other date functions in Parallel jobs but it would be complicated to implement ?

any help would be appreciated..

Thanks in advance.

Sandeep
Regards,
Sandeep Jajee
srinivas.g
Participant
Posts: 251
Joined: Mon Jun 09, 2008 5:52 am

Post by srinivas.g »

Use the below logic

DateFromJulianDay(JulianDayFromDate(Input Column)-60)

If date is not valid means, it will take next date.
Srinu Gadipudi
sandeepJajee
Participant
Posts: 12
Joined: Sat Jun 27, 2009 5:44 am

Post by sandeepJajee »

Hi,

As you stated to subtract 60 days from date but when it comes to Leap yaer and if month contains 30 and 31..then it wn't work.

Ex: Input date=2009-04-30

output date=(2009-04-30)-60 days =2009-03-01

My output date required =2009-02-28

Keep same DD if it is valid after conversion else move the correct date for that month.

Any ideas are welcome.

Thanks,
Regards,
Sandeep Jajee
srinivas.g
Participant
Posts: 251
Joined: Mon Jun 09, 2008 5:52 am

Post by srinivas.g »

Use the below logic

DateFromJulianDay(JulianDayFromDate(Input Column)-60)

After check whether the date is valid or not .If valid means use the same
\If it is niot valid means check the whether year is leap or not ,If year is leap year the date -2 else date-1.

It will resoleve your problem(Use stage variabels for acehiving this logic).
Srinu Gadipudi
Post Reply