- Posts: 371
- Thank you received: 3
Converting two digit year to four digit year
10 years 6 months ago #6421
by ckelsoe
Converting two digit year to four digit year was created by ckelsoe
I am trying to fix two digit years to four digits. In .net this is a one line process. In the scripting language it is a royal pain. This is the code I am trying to make work.
or
This does not work. Basically I want any two digit value from 21 to 99 to have 19 put in front of it. Two digit years between 00 and 20 will have 20 put in front of it.
Code:
var twodigityear : string;
begin
twodigityear := 01;
if twodigityear > 20 and twodigityear <= 99 then
result := '19' + twodigityear
else
result := '20' + twodigityear;
end;
or
Code:
var twodigityear : string;
begin
twodigityear := '15';
if twodigityear > '20' and twodigityear <= '99' then
result := '19' + twodigityear
else
result := '20' + twodigityear;
end;
This does not work. Basically I want any two digit value from 21 to 99 to have 19 put in front of it. Two digit years between 00 and 20 will have 20 put in front of it.
Please Log in or Create an account to join the conversation.
10 years 6 months ago #6444
by ckelsoe
Replied by ckelsoe on topic Re: Converting two digit year to four digit year
Tried this also:
I guess pascalscript does not have a "between" function.
Code:
var TwoDigitYear, FourDigitYear : string;
begin
TwoDigitYear := 99;
if (TwoDigitYear > 00 or TwoDigitYear < 19) then
FourDigitYear := 2000 + TwoDigitYear
else
FourDigitYear := 19 + TwoDigitYear;
Result := FourDigitYear;
end;
I guess pascalscript does not have a "between" function.
Please Log in or Create an account to join the conversation.
10 years 6 months ago #6447
by admin
Mike
ETL Architect
Replied by admin on topic Re: Converting two digit year to four digit year
Well TwoDigitYear is a string so it should be in quotes
var TwoDigitYear, FourDigitYear : string;
begin
TwoDigitYear := '99';
if (TwoDigitYear > '00') or (TwoDigitYear < '19') then
FourDigitYear := '2000' + TwoDigitYear
else
FourDigitYear := '19' + TwoDigitYear;
Result := FourDigitYear;
end;
var TwoDigitYear, FourDigitYear : string;
begin
TwoDigitYear := '99';
if (TwoDigitYear > '00') or (TwoDigitYear < '19') then
FourDigitYear := '2000' + TwoDigitYear
else
FourDigitYear := '19' + TwoDigitYear;
Result := FourDigitYear;
end;
Mike
ETL Architect
Please Log in or Create an account to join the conversation.
10 years 6 months ago #6449
by ckelsoe
Replied by ckelsoe on topic Re: Converting two digit year to four digit year
Tried that. The issue is that there is no way apparently to restrict the test to values between 00 and 19 (2000 and 2019) or the reverse - between 20 and 99 (1920 and 1999).
Code:
var TwoDigitYear, FourDigitYear : string;
begin
TwoDigitYear := '99';
if (TwoDigitYear > '00') or (TwoDigitYear < '19') then
FourDigitYear := '20' + TwoDigitYear
else
FourDigitYear := '19' + TwoDigitYear;
Result := FourDigitYear;
end;
Please Log in or Create an account to join the conversation.
10 years 6 months ago #6450
by ckelsoe
Replied by ckelsoe on topic Re: Converting two digit year to four digit year
Ahh success (I think)...
Code:
var TwoDigitYear, FourDigitYear : string;
begin
TwoDigitYear := [F001];
if (TwoDigitYear < '19') then
FourDigitYear := '20' + TwoDigitYear
else
FourDigitYear := '19' + TwoDigitYear;
Result := FourDigitYear;
end;
Please Log in or Create an account to join the conversation.