Wednesday, May 5, 2010

String to Date conversion (30-dec-2009 to 12/30/2009) in PeopleCode

String to Date conversion (30-dec-2009 to 12/30/2009) in PeopleCode

Below is the code to convert the string to date (30-dec-2009 to 12/30/2009)
&str1 = &array [5];
If &array [5] = "NULL" Then
&oSStu2Tbl.date = "" | "NULL";
&fileLog.WriteLine("&oSStu2Tbl.date = " | &oSStu2Tbl.date);

End-If;
If &str1 <> "" And
Len(&str1) = 9 Then
&str2 = Substring(&str1, 1, 2);
&str3 = Substring(&str1, 4, 3);
Evaluate &str3
When = "Jan"
&mm = 1;
Break;
When = "Feb"
&mm = 2;
Break;
When = "Mar"
&mm = 3;
Break;
When = "Apr"
&mm = 4;
Break;
When = "May"
&mm = 5;
Break;
When = "June"
&mm = 6;
Break;
When = "July"
&mm = 7;
Break;
When = "Aug"
&mm = 8;
Break;
When = "Sep"
&mm = 9;
Break;
When = "Oct"
&mm = 10;
Break;
When = "Nov"
&mm = 11;
Break;
When = "Dec"
&mm = 12;
Break;

End-Evaluate;

rem &b = Month(&str3);

&str4 = Substring(&str1, 8, 2);
&dte = &str2 | "/" | &mm | "/" | &str4;

&oSStu2Tbl.S_STU_DATE = &dte;
&fileLog.WriteLine("&oSStu2Tbl.date = " | &str2 | "/" | &mm | "/"|&str4);
End-If;

If &str1 <> "" And
Len(&str1) = 8 Then
&str2 = Substring(&str1, 1, 1);
&str3 = Substring(&str1, 3, 3);
Evaluate &str3
When = "Jan"
&mm = 1;
Break;
When = "Feb"
&mm = 2;
Break;
When = "Mar"
&mm = 3;
Break;
When = "Apr"
&mm = 4;
Break;
When = "May"
&mm = 5;
Break;
When = "June"
&mm = 6;
Break;
When = "July"
&mm = 7;
Break;
When = "Aug"
&mm = 8;
Break;
When = "Sep"
&mm = 9;
Break;
When = "Oct"
&mm = 10;
Break;
When = "Nov"
&mm = 11;
Break;
When = "Dec"
&mm = 12;
Break;

End-Evaluate;

rem &b = Month(&str3);
&str4 = Substring(&str1, 7, 2);
&dte = &str2 | "/" | &mm | "/" | &str4;
&oSStu2Tbl.S_STU_DATE = &dte;
&fileLog.WriteLine("&oSStu2Tbl.date = " | &str2 | "/" | &mm | "/" | &str4);
End-If;

No comments:

Post a Comment