Adding 1 to an year part of the date field

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
WoMaWil
Participant
Posts: 482
Joined: Thu Mar 13, 2003 7:17 am
Location: Amsterdam

Post by WoMaWil »

Hi Santosh,

If all your dates are in the way you showed you can devide the date in two partial strings:
one for the year: MyYear=MyDate[4]
and one for the Rest MyRest=Mydate[1,7]
then you add one to the year: MyYear+=1
and you put the parts together: MyNewDate=MyRest:MyYear
That's it!

Wolfgang

I am trying to add 1 to an year part of the date field.
eg. 20-JAN-1998 + 1 = 20-JAN-1999.
Any suggestions on doing this in a simplified way.

Thanks in advance

Santosh



chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Be careful with simple solutions like this, they will work fine for the most part, but once in a while generate an invalid date. For example, bump a leap-year Feb 29th by a year.

I haven't tried this myself, but you might try doing the Iconv/Oconv pair thing and adding 365 to the internal date...

-craig
DSGuru
Participant
Posts: 16
Joined: Fri Feb 15, 2002 4:46 pm

Post by DSGuru »

Hi Santosh,

The problem of simple solution is 02/29/2000 + 1 = 02/29/2001 (There's no such date, just like one of the helper mentioned)

you have to split the date into 3 portion, yyyy, mm, dd
then use the yyyy to test for leap year by mod it by 4 and remainder is 0. If it's leap year then check the month to see if it's 02 (Feb), if it's Feb and the date is 29 then minus 1 for it to be 28 then you can add 1 to the year, else just add 1 to the year.


Take care and good luck.

Leon
Post Reply