Date Conversion?

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
A_SUSHMA
Participant
Posts: 43
Joined: Fri Apr 12, 2013 10:34 am

Date Conversion?

Post by A_SUSHMA »

Hi All,

I have one requirement.

Requirement: Take the current date and check the date if day is >20 then take the month as current month Else take the previous month with day as 01 always.

Ex: 21-02-2014 .here day is greater then 20 output= 01-02-2014
02-03-2014 here day is less than 20 take the previous month date : 01-02-2014


Could you please help me the above?
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Use functions MonthDayFromDate(), MonthFromDate() and YearFromDate() to extract the components, do your math, then use DateFromComponents() function to re-assemble the date.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
A_SUSHMA
Participant
Posts: 43
Joined: Fri Apr 12, 2013 10:34 am

Post by A_SUSHMA »

Thanks Ray.... working fine
qt_ky
Premium Member
Premium Member
Posts: 2895
Joined: Wed Aug 03, 2011 6:16 am
Location: USA

Post by qt_ky »

MonthDayFromDate() would not be necessary, as the resulting day of the month is always day 1.

Make sure to test dates ranges including January 1st through 20th, to ensure it falls back to the previous year.

:idea: You may be able to avoid the "check the date if day is > 20" and similar "If Then Else" logic by doing the date math up front. Would this work?

Stage variable:

Code: Select all

svTempDate = DateOffsetByDays(incoming_date, -20)
Derivation:

Code: Select all

DateFromComponents(YearFromDate(svTempDate), MonthFromDate(svTempDate), 1)
Choose a job you love, and you will never have to work a day in your life. - Confucius
Post Reply