Page 1 of 1

Convert 2 digit year to 4 digits

Posted: Thu Oct 27, 2011 6:21 am
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

Posted: Thu Oct 27, 2011 7:01 am
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.

Posted: Thu Oct 27, 2011 7:14 am
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?

Posted: Thu Oct 27, 2011 7:16 am
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.

Posted: Thu Oct 27, 2011 7:22 am
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.

Posted: Thu Oct 27, 2011 8:19 am
by max.madsen
Of course..
My post was a tip for karthi think about the transformation's intelligence.. :wink:

Re: Convert 2 digit year to 4 digits

Posted: Thu Oct 27, 2011 8:26 am
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....