cancel
Showing results for 
Search instead for 
Did you mean: 

Date format change

Former Member
0 Kudos

Hi

I am getting date format from source in 4 different formats(1.YYYY/MM/DD)(2.MM//DD//YYYY)(3.DD//MM//YYYY)(4.YY//MM/DD). In this which format will come don't no,but i have to send (YYYY/MM/DD) format at receiver.so how to handle this. if its UDF please provide me correct UDF.

Accepted Solutions (1)

Accepted Solutions (1)

markangelo_dihiansan
Active Contributor
0 Kudos

Hi Bhagya,

Here is a UDF:

The code is below


for(int a=0;a<inp.length;a++){

  int len = inp[a].length();

  SimpleDateFormat input;

  SimpleDateFormat otput = new SimpleDateFormat("yyyy/MM/dd");

  Date date;

  if(len == 10){

  result.addValue(inp[a]);

  }

  else if(len == 9){

  try{

  input = new SimpleDateFormat("yy//MM/dd");

    date = input.parse(inp[a]);

    result.addValue(otput.format(date));

  }

  catch(Exception e){

  e.getMessage();

  }

  }

  else if(len == 12){

  String year = inp[a].substring(inp[a].lastIndexOf("/")+1);

  String res;

  try{

    input = new SimpleDateFormat("MM//dd//yyyy");

    date = input.parse(inp[a]);

    res = otput.format(date);

    if(res.indexOf(year)>-1){

      result.addValue(res);

    }

    else{

      try{

      input = new SimpleDateFormat("dd//MM//yyyy");

      date = input.parse(inp[a]);

      result.addValue(otput.format(date));

      }

      catch(Exception e){

        e.getMessage();

      }

    }

   }

   catch(Exception e){

    e.getMessage();

   }

  }

}

Testing:

Hope this helps,

Mark

Former Member
0 Kudos


Hi Mark,

Many Thanks.

Bhagya.

Answers (5)

Answers (5)

Former Member
0 Kudos

Hello,

If you have this date 01/02/03.

How can you interprete this ? 01 feb 2003 or 02 Jan 2003 or maybe 03 feb 2001 or ...

This is not accurate at all. Maybe if you add something in your payload (a flag) to know in what case your UDF will format your date, otherwise you will never get a correct date format in many cases.


Best regards,

Sako

nabendu_sen
Active Contributor
0 Kudos

Ok, so I missed that it may come with any random format. I don't think any stable system works in that way. It has to be in some specific format. Or they need to send a KEY field within the message to identify in which format they generated the Date.

Regards,

Nabendu.

Former Member
0 Kudos

Hi

kindly tell me one example how to differentiate with the key field.

manigram
Active Participant
0 Kudos

Hi,

Use multipe IF conditions and try to convert it in to required format.

Regards,

Manigandan

RaghuVamseedhar
Active Contributor
0 Kudos

Bhagya,

It is not possible to write a programming logic for this requirement.

Let's say source system sends "06/11/2015". Is it Jun 11th   OR   6th Nov? Is it dd/MM/yyyy or MM/dd/yyyy?

Please request source system to send consistent date format.

Former Member
0 Kudos


Raghu,

As per your example its difficult to identify the format.

Thanks.

Former Member
0 Kudos

Hi Bhagya,

You will to use a series of sandard function along withDate tranform functions to achieve this. You need to check the date format and based on that map he daa.

Let me know if you need any more inputs

Regards

Sriram

nabendu_sen
Active Contributor
0 Kudos

Use DateTrans function available with Standard Mapping functions in PI.

Check: SAPTechnical.COM - Date conversions in XI / PI