cancel
Showing results for 
Search instead for 
Did you mean: 

UDF to get the next Business Day

Former Member
0 Kudos

Hi,

Could someone please provide me the code for  simple UDF to get the next Business Day?

Thanks in Advance.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Anuradha,

Please try it with below code,

Date today
= new Date();

    Calendar calendar = Calendar.getInstance();

        calendar.setTime(today);

        int dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK);

        if (dayOfWeek == Calendar.FRIDAY)
        {
            calendar.add(Calendar.DATE, 3);
        }
        else if (dayOfWeek == Calendar.SATURDAY)
        {
            calendar.add(Calendar.DATE, 2);
        }
        else
        {

            calendar.add(Calendar.DATE, 1);

        }
        Date nextBusinessDay = calendar.getTime();

        int y = calendar.get(Calendar.YEAR);

        int d = calendar.get(Calendar.DAY_OF_MONTH);

        int m =calendar.get(calendar.MONTH)+1;

        String dd = d+"";

        String mm =    m+"";

        if(dd.length()==1)

            dd = "0"+dd;

        if(mm.length()==1)

            mm = "0"+mm;


return ""+y+""+mm+""+dd;

Answers (2)

Answers (2)

Former Member
0 Kudos

Thanks for the inputs.

iaki_vila
Active Contributor
0 Kudos

Hi Anuradha,

The business days change in every country, region, city and so on. You will need a system that you have the business calendar loaded, if you have a SAP ECC in your environment you can try with a RFC lookup to take this information.

Regards.