Skip to Content
avatar image
Former Member

Adding 2 Business days into the given date in SAP PI

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.

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

2 Answers

  • Best Answer
    Jul 05, 2017 at 04:09 PM

    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

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Jul 10, 2017 at 06:17 PM

    Thanks .This is working as expected .

    Add comment
    10|10000 characters needed characters exceeded