cancel
Showing results for 
Search instead for 
Did you mean: 

Increase the datestamp by 60 days in idoc

former_member190358
Participant
0 Kudos

Hello Everyone,

I have a logic to implement, based on some condition.

The condition is to check one field of IDoc. If this is true than the value of the date should be increased by 60 days.

If date is today like 27th August 2012, than the date should 27/08 + 60 days = 26th October 2012

What is the best way to achieve this solution .

Please provide your inputs.

Regards,

Ravi

Accepted Solutions (1)

Accepted Solutions (1)

former_member184681
Active Contributor
0 Kudos

Hi Ravi,

Use a simple UDF function for that purpose, for instance something like that:

SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");

Calendar c = Calendar.getInstance();

c.setTime(sdf.parse(input));

c.add(Calendar.DATE, 60);  // number of days to add

System.out.println(sdf.format(c.getTime()));

Your function has to import java.text.SimpleDateFormat library and take one input parameter of type String, called simply input.

Regards,

Greg

former_member190624
Active Contributor
0 Kudos

Hi Greg,

But code throwing error at sdf.parse(input) ...

Regards

Hari.

former_member184681
Active Contributor
0 Kudos

Hi,

I'm quite surprise, I tested the code before posting it. Did you follow this advice, too?

Your function has to import java.text.SimpleDateFormat library and take one input parameter of type String, called simply input.

If so, please let me know the exact error description that you have. Only now I have spoted one more thing. Of course in PI UDF, use:

return sdf.format(c.getTime());

instead of:

System.out.println(sdf.format(c.getTime()));

Regards,

Greg

rajasekhar_reddy14
Active Contributor
0 Kudos

Hi Hari,

Greg code should work   paste your UDF code screenshot here.

Regards,

Raj

baskar_gopalakrishnan2
Active Contributor
0 Kudos

>c.setTime(sdf.parse(input));

You have to create user defined function and pass "input" as java string type as argument. Hope you did that. If not do that. The next important thing is the code miss try and catch block

something like this ...

 

create your method Signature (String input)  {

 
  SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");

  Calendar c = Calendar.getInstance();
  try{
   c.setTime(sdf.parse(input));
   c.add(Calendar.DATE, 60);  // number of days to add
     
     }catch(Exception e){
 
     }
     return sdf.format(c.getTime());
}

former_member190624
Active Contributor
0 Kudos

Hi Greg,

Yes code working correctly , but i didn't included try{}catch() block .Now , code working fine .Thanks

former_member190358
Participant
0 Kudos

Hello Greg and Baskar,

It worked for me as well.. Hence closing the thread !!

Answers (0)