DataStage – How to add or subtract from a date in a transformer stage

DataStage – How to add or subtract from a date in a transformer stage

From time to time there is a need to adjust a date within a DataStage transformer.  It could be as small subtracting a day to set a batch processing date to yesterday or something bigger.  If you need to adjust a date by a year, month and/or day the DateOffsetByComponents function is the method.  The DateOffsetByComponents function can work with a fixed value or input from the job either; an input field, or a stage variable.  The main thing is knowing what to put in which position in the offset values with the understanding that offsets values can be positive or negative, thereby, allowing the addition and subtraction of different part of a date in a dataStage transformer.

Purpose of DateOffsetByComponents Function

  • This function is used to obtain a specific required date by applying offset to a given date.

Syntax

DateOffsetByComponents(<<Input Date>>, year offset, month offset, day of month offset)

How to subtract a year

DateOffsetByComponents(dsjobstartdate,-1, 0, 0)

How to add a year

DateOffsetByComponents(dsjobstartdate ,1, 0, 0)

How to subtract a month

DateOffsetByComponents(dsjobstartdate, 0, -1, 0)

How to add a month

DateOffsetByComponents(dsjobstartdate, 0, 1, 0)

How to subtract a day

DateOffsetByComponents(dsjobstartdate, 0, 0, -1)

How to add a day

DateOffsetByComponents(dsjobstartdate, 0, 0, 1)

%d bloggers like this: