Convert 2 digit year to 4 digits

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
karthi_gana
Premium Member
Premium Member
Posts: 729
Joined: Tue Apr 28, 2009 10:49 pm

Convert 2 digit year to 4 digits

Post by karthi_gana »

All,

I would like to convert two digit year to four digit.

say for example, i have the below data in a file.

91
92
93
94
95
96
97
98
99
00
01
02
03
04
05
06
07
08
09
10
11

I have to convert this as

1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
Karthik
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

I don't know if there is something more "official" but I'd probably look at using StringToDate & DateToString to convert this. Add something like "-01-01" to the two-digit year, convert to date and then back to string using only "%yyyy" for the format.
-craig

"You can never have too many knives" -- Logan Nine Fingers
max.madsen
Premium Member
Premium Member
Posts: 62
Joined: Tue Dec 07, 2004 7:41 am
Location: Brasil
Contact:

Post by max.madsen »

The problem will do a logic for choose when input "91" shall transform in "1991" or "2091" ou "2191"... How you will choose?
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

max.madsen wrote:The problem will do a logic for choose when input "91" shall transform in "1991" or "2091" ou "2191"... How you will choose?
That decision would possibly be based on the CENTURYPIVOT setting.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

True, there's always something controlling the "century pivot" aspect of conversions of two-digit to four-digit years. Of course, you can easily do your own simple if-then-else check and stick the century on yourself.
-craig

"You can never have too many knives" -- Logan Nine Fingers
max.madsen
Premium Member
Premium Member
Posts: 62
Joined: Tue Dec 07, 2004 7:41 am
Location: Brasil
Contact:

Post by max.madsen »

Of course..
My post was a tip for karthi think about the transformation's intelligence.. :wink:
reddy.vinod
Participant
Posts: 36
Joined: Mon Jul 16, 2007 3:37 am
Location: USA

Re: Convert 2 digit year to 4 digits

Post by reddy.vinod »

SV1: Right(YearFromDate(CurrentDate()),2)
SV2: If Input <=SV1 then '20':Input Else '19':Input

Mostly we uses this logic, i hope it will solve your problem....
VINOD
Post Reply