Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

How to skip weekend dates

Hi all,

In one of my MM, I am getting a date in MM/DD/YY format (after some validations) and then the requirement says, if this date is any of the weekday, then pass the same. But if the date is a weekend (SAT and SUN) then get the date of following Monday.

Ultimately the target date should be a weekday.

Can you help me with some UDF example.

Former Member
Former Member replied

Hi Murly,

You can try with this function.

import java.text.SimpleDateFormat;

import java.util.Calendar;

import java.util.Date;

public String validateDate(String date){

try{

SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yy");

SimpleDateFormat sdfDayName = new SimpleDateFormat("EEEE");

Calendar ca = Calendar.getInstance();

ca.setTime(sdf.parse(date));

if (sdfDayName.format(ca.getTime()).equals("Saturday") || sdfDayName.format(ca.getTime()).equals("Sunday")){

ca.add(Calendar.DATE,1);

}

return sdf.format(ca.getTime());

}catch(Exception ex){

System.out.println(ex.toString());

}

return date;

}

I hope this helps you.

BRegards

Ivan

0 View this answer in context

Helpful Answer

by
Not what you were looking for? View more on this topic or Ask a question