Skip to Content
0

Adding 2 Business days into the given date in SAP PI

Jul 05, 2017 at 10:50 AM

44

avatar image
Former Member

Dear Experts,

We have a requirement to add 2 business days into given date in SAP PI.

Suppose we get date as 30/06/2017 , then we need to pass as 04/07/2017

As 30/06/2017 : Friday , so need to remove saturday and Sunday , need to add 2 business days , so Tuesday.

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

2 Answers

Best Answer
avatar image
Former Member Jul 05, 2017 at 04:09 PM
1

Hi Anik,

Use below code. Additionally import - java.text.SimpleDateFormat in your UDF.

Calendar cal = new GregorianCalendar();
int dayCount = 0;

try {
Date convertedDate = new SimpleDateFormat("dd/MM/yyyy", Locale.ENGLISH).parse(inputDate[0]);
cal.setTime(convertedDate);
} catch(Exception e) {
e.printStackTrace();
}

for(int i=0;i<2;) {
cal.add(Calendar.DAY_OF_MONTH, 1);
int dayOfWeek = cal.get(Calendar.DAY_OF_WEEK);
if (dayOfWeek == Calendar.SUNDAY || dayOfWeek == Calendar.SATURDAY)
i--;
i++;
}

Date date = cal.getTime();
SimpleDateFormat s=new SimpleDateFormat("dd/MM/yyyy");

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

Thanks,

Apu


pshvh.png (130.7 kB)
Share
10 |10000 characters needed characters left characters exceeded
avatar image
Former Member Jul 10, 2017 at 06:17 PM
0

Thanks .This is working as expected .

Share
10 |10000 characters needed characters left characters exceeded