cancel
Showing results for 
Search instead for 
Did you mean: 

How to skip weekend dates

Former Member
0 Kudos

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.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

if possible, can you send me the UDF code using those functions.

Former Member
0 Kudos

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

Answers (4)

Answers (4)

Former Member
0 Kudos

Hi murli,

Try this it will work, while mapping to target mao it with SplitbyValue function;

Source -> udf -> splitbyvalue - >target

import : java.text.SimpleDateFormat;java.util.Calendar;java.lang.;java.util.GregorianCalendar;java.util.;java.text.*;java.util.Date;java.text.DateFormat;

int co = a[0].length();

String[] expDate = new String[co];

Date[] dat = new Date[co];

Date[] bar = new Date[co];

int[] st = new int[co];;

try

{

for(int i=0;i<co;i++)

{

dat<i> = new SimpleDateFormat("dd/MM/yyyy").parse(a<i>);

Calendar cal = new GregorianCalendar();

cal.setTime(dat<i>);

st<i> = cal.get(Calendar.DAY_OF_WEEK);

if((st<i> == 2) || (st<i> == 3) || (st<i> == 4) || (st<i> == 5) || (st<i> == 6))

{

bar<i> = cal.getTime();

expDate<i> = new SimpleDateFormat("MM/dd/yyyy").format(bar<i>);

result.addValue(expDate<i>);

}

else if((st<i> == 1) && (st<i> == 7))

{

result.addValue(ResultList.SUPPRESS);

}

}

}

catch(Exception ex)

{

System.out.println(ex);

}

regards,

Murugavel

former_member190389
Active Contributor
0 Kudos

Hi,

Please see the code


String sDate = "12/07/08";
		
			SimpleDateFormat sd = new SimpleDateFormat("MM/dd/yy");
			Date dt = sd.parse(sDate);

			Calendar cal = new GregorianCalendar();
			cal.setTime(dt);
			
			int day = dt.getDay();
			
			if (day == 0 )
			cal.add(dt.getDate(), +1);		

			if(day == 6)
			cal.add(dt.getDate(), +2);
				
			System.out.println("Date is "+ sd.format(cal.getTime()));
			
			 	

prateek
Active Contributor
0 Kudos

To clarify a bit on above reply, there are certain java classes which could be used to access the date related operations.

java.util.Calendar;java.text.SimpleDateFormat;java.text.DateFormat;

From there you may perform operations like accessing day for any date. Then using standard function, you may check whether the day is Sunday or Saturday. If it is, then pass monday.

Regards,

Prateek

Former Member
0 Kudos

Use the DAY_OF_WEEK functionality of Calendar class.