Page 1 of 1

Implementing date logic

Posted: Wed Jul 24, 2013 5:17 pm
by raji33
Hi

Can any one help me with this scenario.

I have current date, If current date falls in between

yyyy-mm-02,
!
!
!yyyy-mm-05 of month then get the last date of previous month.

for ex:current date =2013-07-02 then i need to populate as 2013-06-30
simillarly if date falls as 2013-07-03 then also its 2013-06-30

Thanks

Re: Implementing date logic

Posted: Wed Jul 24, 2013 6:33 pm
by SURA
This can be done using different ways.

I would prefer to get the value from DB itself.

If your source is DB, then you can bring an additional column called First Date Of the month with value. Then that date can be compared in Datastage.

Posted: Wed Jul 24, 2013 6:56 pm
by moalik
Hi Raji,

In DataStage we have a Transform called MONTH.FIRST.

This Transform Returns a numeric internal date corresponding to the first day of a month given in MONTH.TAG format (YYYY-MM).
Example: MONTH.FIRST("1993-02") => 9164".

For your logic Fetch "YYYY-MM" from your input column and use this transform. Once you get the Numeric internal date from that subtract 1 from the value.

Example: MONTH.FIRST("1993-02") => 9164" , this is the 1st Day of the month,to get the last month last date just do "9164-1" which gives 9163.

The convert the result using oconv(result,"D-YMD[4,2,2]").

Now just compare the dates in and pass the above value once the condition is satisfied.

Hopes this answers your solution. :)

Posted: Wed Jul 24, 2013 7:21 pm
by SURA
YES for SERVER JOBS. But the request is for PARALLEL JOB.

Posted: Wed Jul 24, 2013 8:22 pm
by ray.wurlod
Transforms are available in BASIC Transformer stage.

Posted: Wed Jul 24, 2013 8:24 pm
by ray.wurlod
In parallel Transformer stage, use MonthDayFromDate() to determine the day number for your range check. Use DateFromDaysSince() and that value to calculate the date of the first day of the current month or the last day of the previous month.

Posted: Thu Jul 25, 2013 8:42 am
by priyadarshikunal
Check this post for a starter. apart for this you need to add logic to find if the data is between the range you want.

Posted: Thu Jul 25, 2013 4:43 pm
by ray.wurlod
You might also consult the FAQ post on Common Date Offsets in Parallel Jobs