on 08-27-2012 3:47 PM
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
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
>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());
}
User | Count |
---|---|
91 | |
10 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.