Calculate Previous Month with year

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
Vrisha
Premium Member
Premium Member
Posts: 60
Joined: Sat Jul 15, 2017 9:32 pm
Location: Texas,USA

Calculate Previous Month with year

Post by Vrisha »

I have requirement where I need to populate the Column 'BK' with previous month with year.

Column - BK - Datatype - Number(6)- Format -YYYYMM

Current month, the job should run for previous month data based on the BK.

I tried the option MonthFromDate(CurrentDate())-1 ---> it is giving '8' for today. I want it as '08'

Like that I can take yearfromDate() and concatenate.

But the problem will be when next year 2018 comes, this above logic won't work.

Please let me know if there is any function to do this.

Thanks.
Suja
Vrisha
Premium Member
Premium Member
Posts: 60
Joined: Sat Jul 15, 2017 9:32 pm
Location: Texas,USA

Post by Vrisha »

Resolved the problem

Steps:
Stage variables
MonthFromDate(CurrentDate())-1=svPrevMonth-varchar

If Len(svPrevMonth)=1 then '0':svPrevMonth else svPrevMonth=svConMonth-varchar

YearFromDate(CurrentDate())=svYear-Varchar

YearFromDate(CurrentDate())-1=svYearCheck-varchar

If svConMonth=12 then svYearcheck:svConMonth else svYear:svConMonth=svConYearMonth-varchar

In Transformer
svConYearMonth......>BK
Suja
Post Reply