Skip to Content

UDF to get the next Business Day

Hi,

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

Thanks in Advance.

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

3 Answers

  • Best Answer
    avatar image
    Former Member
    Sep 08, 2015 at 09:19 AM

    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;

    Add comment
    10|10000 characters needed characters exceeded

  • Sep 08, 2015 at 09:25 AM

    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.

    Add comment
    10|10000 characters needed characters exceeded

  • Sep 08, 2015 at 10:03 AM

    Thanks for the inputs.

    Add comment
    10|10000 characters needed characters exceeded