cancel
Showing results for 
Search instead for 
Did you mean: 

String as date (conversion)

Former Member
0 Kudos

Hi,

Can someone help me out please with a UDF that gets an input string, but it needs to look at that string as if it is a date, and then transform that string to another format.

The input string can be empty or contain 8 zeroes ("" or "00000000") and if that happens the UDF must return "", and of course no transformation can be done then.

If the string is not empty or zeroes, the transformation will be yyyymmdd to dd-mm-yyyy.

Kind regards

Robert

Accepted Solutions (0)

Answers (4)

Answers (4)

Former Member
0 Kudos

Hi, I knew about the possibility of a full graphical mapping but asked explicitly for a UDF for esthetical reasons.

I managed it with some held from other sources with the following code:

String result;

if (a.startsWith("0") || a.length() != 😎 {

result = "";

} else {

result = a.substring(6)"."a.substring(4,6)"."a.substring(0,4);

}

return result;

Thx anyway for replying

Former Member
0 Kudos

use the mapping as below


date(source field)---->equalS--->or-->ifWithoutelse---->UDF----date(target field)
constant[]/                    |
date(source field)---->equalS/
constant[00000000]/

u will find the sample java code to convert from one date format to another date format search online and write it as UDF.

former_member181962
Active Contributor
0 Kudos

HI,

YOu can make use of the date function (dateTrans)Transformdate with input format as yyyymmdd and output format as dd-mm-yyyy.

Path : double click on the mapping editor area.

All functions->Date Functions->Datetrans

Regards,

ravi

Shabarish_Nair
Active Contributor
0 Kudos

>

> Hi,

>

>

> Can someone help me out please with a UDF that gets an input string, but it needs to look at that string as if it is a date, and then transform that string to another format.

> The input string can be empty or contain 8 zeroes ("" or "00000000") and if that happens the UDF must return "", and of course no transformation can be done then.

>

> If the string is not empty or zeroes, the transformation will be yyyymmdd to dd-mm-yyyy.

>

>

> Kind regards

> Robert

you can utilize the standard date function - datetrans

for your check on if it a zero or empty string you can utilize the standard string function equalsS along with the boolean if else function

http://help.sap.com/saphelp_nw04/helpdata/en/43/c4cdfc334824478090739c04c4a249/content.htm