Subtract Year

Post questions here relative to DataStage Server Edition for such areas as Server job design, DS Basic, Routines, Job Sequences, etc.

Moderators: chulett, rschirm, roy

Post Reply
shiva459
Premium Member
Premium Member
Posts: 100
Joined: Wed Jun 11, 2003 1:49 am
Location: Bangalore

Subtract Year

Post by shiva459 »

Hi

I am trying to subtract year from a given date format but not able to succeed.The input format is 01/15/2005 and my output should be something like 01/15/2002.Please help me in acheiving this.

Thanks
Sainath.Srinivasan
Participant
Posts: 3337
Joined: Mon Jan 17, 2005 4:49 am
Location: United Kingdom

Post by Sainath.Srinivasan »

Simplest way may be to split the year separately and concat it back after the computation.
shiva459
Premium Member
Premium Member
Posts: 100
Joined: Wed Jun 11, 2003 1:49 am
Location: Bangalore

Post by shiva459 »

Hi Sainath

I tried doing that but my comparison logic is not working properly.

I have to compare the output with another date of same format but for some reasons it is not giving correct results.Please advice.
ketfos
Participant
Posts: 562
Joined: Mon May 03, 2004 8:58 pm
Location: san francisco
Contact:

Post by ketfos »

Hi,

You can use following routine where

Arg1 is the input date (01/15/2005)
Arg2 is another date (01/11/1999)
Arg3 is number of years you want to substract from input date(Arg1)
----------
Ans1 = Arg1[7,4] - Arg3

Ans2 = Arg1[1,6]:Ans1

Ans3 = Iconv(Ans2,"D2")
Ans4 = Oconv(Ans3,"D")
Ans5 = Oconv(Arg2,"D")

IF Ans3 > Iconv(Arg2,"D2") then
Ans = Ans4 : ' GT ' : Ans5
end
else
Ans = Ans4 : ' LT ' : Ans5
end

----
Ketfos
talk2shaanc
Charter Member
Charter Member
Posts: 199
Joined: Tue Jan 18, 2005 2:50 am
Location: India

Post by talk2shaanc »

ketfos wrote: Ans3 = Iconv(Ans2,"D2")
Ketfos
above is incorrect, the format D2 is for a date value say; 25 MAY 05

Correct format would be:
Ans3= Iconv(Ans2, "D/MDY[2,2,4]")
Shantanu Choudhary
ketfos
Participant
Posts: 562
Joined: Mon May 03, 2004 8:58 pm
Location: san francisco
Contact:

Post by ketfos »

Hi,
You had mentioned that routine is not correct.
If will not matter what date mask you use in Oconv function which is
just the display format.
You can output the date in diferent formats in Oconv, still it is going to to return correct results, irrespective of the date format.
As long as input format is like 01/15/2005, the results will be ok.

Thanks
Ketfos
WoMaWil
Participant
Posts: 482
Joined: Thu Mar 13, 2003 7:17 am
Location: Amsterdam

Post by WoMaWil »

You can simply work with the iconv and oconv-functions.

You american may ignore it, but there are a lot of date-formats around the world even for the christian (gregorianian) Dateformat. You first have to check which one you have as source.

if you have for sure "two for month"-"slash"-"two day"-"slash"-"four for the year" you always have with slashes 10 characters. (If you have something else or something variable as dateformat you first have to bring it via iconv and oconv in a fix format (always the same number of charactes).

Then you divide into the rest an the year, for the above example it is:
*** Transfer Argument to variable
MyDate=Arg1
YearsToAdd=Arg2
*** make year-Part = last 4 characters
MyYear=MyDate[4]
*** make moth-day-Part = first 6 characters
MyMonthDay=MyDate[1,6]
*** substract (-) or add (+) years
NewYear=MyYear+YearsToAdd
*** Unite Yearpart and MothDayPart
Ans=MyMonthDay:NewYear


So simply copy the brown text in a routine an choose two arguments. Thats it. As mentioned if you have other dateformats or variable Date-formats you have to change it a bit.

Have an nice day
Wolfgang
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Don't forget to check that the day and month are valid for the new year. For example, subtracting one year from 2004-02-29 should not return 2003-02-29 because this is not a valid date. What it should return you will need to decide, and then document as a business rule (in the long description of the Routine at the very least).
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
talk2shaanc
Charter Member
Charter Member
Posts: 199
Joined: Tue Jan 18, 2005 2:50 am
Location: India

Post by talk2shaanc »

ketfos wrote:Hi,
You had mentioned that routine is not correct.
If will not matter what date mask you use in Oconv function which is
just the display format.
You can output the date in diferent formats in Oconv, still it is going to to return correct results, irrespective of the date format.
As long as input format is like 01/15/2005, the results will be ok.

Thanks
Ketfos
Just replying to your note, I have mentioned the format given for ICONV is incorrect NOT OCONV.
if the format given in ICONV is not same as your input date value, then proper conversion wont happen, and then whatever format you use in OCONV wont give you desired result.
Shantanu Choudhary
elavenil
Premium Member
Premium Member
Posts: 467
Joined: Thu Jan 31, 2002 10:20 pm
Location: Singapore

Post by elavenil »

You can achieve this by OConv(IConv(Arg1,"D/E")-(n*365)-1,"D/E") , where n is the no of years to subtract and the format must be the same as you mentioned in your post.

HTWH.

Regards
Saravanan
Sainath.Srinivasan
Participant
Posts: 3337
Joined: Mon Jan 17, 2005 4:49 am
Location: United Kingdom

Post by Sainath.Srinivasan »

I agree with Ray on the Feb date matter.

You can perform OConv(IConv(dt)) to obtain the correct date in that case.

But the requirement from the initial user is not yet clear as he has stated that he wants to find 'difference' between two dates.
I have to compare the output with another date of same format but for some reasons it is not giving correct results.Please advice.
Post Reply