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){


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

SimpleDateFormat sdfDayName = new SimpleDateFormat("EEEE");

Calendar ca = Calendar.getInstance();


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



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

}catch(Exception ex){



return date;


I hope this helps you.



0 View this answer in context

Helpful Answer

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