cancel
Showing results for 
Search instead for 
Did you mean: 

Tomorrow's date in the mapping

Former Member
0 Kudos

Dear friends,

I have to put tomorrow's date skipping Sunday in the mapping for a date field.

Can anyone help me how to do this?

Kind regards,

Kamran

Accepted Solutions (1)

Accepted Solutions (1)

andresousa
Advisor
Advisor
0 Kudos

Hi Kamran

What I could understand is that you need to check if the day after the current date is a Sunday and, if so, get the date corresponding to the following monday, right?

You can do this by using CurrentDate function and implementing the logic through a udf, with one string input parameter. The input of such UDF is currentDate function. Here's what the code would look like:

PS: You need to import java.text.* and java.util.* for this udf.

Regards and happy new year!

int diaSemana = 0;

try{

DateFormat format = new SimpleDateFormat("yyyy/MM/dd");

Calendar calendar = Calendar.getInstance();

Date date = format.parse(a);

calendar.setTime(date);

diaSemana = calendar.get(Calendar.DAY_OF_WEEK); /weekday/

if (diaSemana == 7) {

calendar.add(Calendar.DATE, 2);

date = calendar.getTime();

return new SimpleDateFormat("MM/dd/yyyy").format(date);

}

else {

calendar.add(Calendar.DATE, 1);

date = calendar.getTime();

return new SimpleDateFormat("MM/dd/yyyy").format(date);

}

} catch (Exception e){ }

return "";

Former Member
0 Kudos

Thank you andre points are rewarded

Answers (3)

Answers (3)

Former Member
0 Kudos

Hi Kamran,

that should be possible without UDF. Please try the following:

1. Use a concat with the following input parameters:

1a)

- currentDate (Target Format EEE)

- the result should be the current weekday (e.g. Mi for Wednesday here in Germany, maybe you got other values for another system installation)

- after the currentDate do FixValues and create a mapping table for the next day (e.g. Mi --> Do). If you want to leave out the Sunday you'll have to use the correct expected day therefore, e.g. Sa --> Mo.

1b)

- currentDate (Target Format MMyyyy)

2. The result of the concat should be the next weekday in letters concatenated with month and year in digits. Now use the DateTrans function with the following parameters:

2a) Source Date: EEEMMyyyy

2b) Target Date: for example yyyyMMdd --> this should be the correct day

Best regards

Lars

Former Member
0 Kudos

Thanks Lars,

I had a question about your solution. What happens if today is on the last day of month?

e.g. Thursday 31-01-2008, with your solution I will get Friday 01-2008 instead of Friday 02-2008.

regards,

Kamran

aashish_sinha
Active Contributor
0 Kudos

Hi,

try DateAfter -> Advance Properties -> set the first weekday to sunday. This may help you to acheive success.

Regards

Aashish Sinha

PS : reward points if helpful

Former Member
0 Kudos

I guess it should be like this:

DateAfter -> Advance Properties -> set the first weekday to MONDAY. And number of days in a week to be set to 6. So that counting will start form mon, tue, wed, thu, fri, sat.

Former Member
0 Kudos

Thank you guys for your reply.

Ive seen that function but for that I need an input field to map it but I dont have an input field I need a function like Current Date so without an input field.

Any suggestion what to do?

regards,

Kamran

aashish_sinha
Active Contributor
0 Kudos

Hi,

you can use the currentDate in graphical mapping for you purpose. XI Functions contains currentdate in Date functions. and then do graphical mapping and then put the output to target structure.

Regards

Aashish Sinha

PS : reward points if helpful

Former Member
0 Kudos

Hi Aashish,

If I use current date I will get the date of today, what I need is the date of tomorrow so 01-03-2008.

Regards,

Kamran

Former Member
0 Kudos

Hi Kamran !

Use this UDF to get the tomorrow date based on the input skipping sunday :

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

public String Tomorrow(String a,Container container){

String notifyDates = a;

Calendar calendar = Calendar.getInstance ( ) ;

DateFormat dateFormat = new SimpleDateFormat ( "yyyy-MM-dd" ) ;

int days=1;

try {

Date date = dateFormat.parse ( notifyDates ) ;

calendar.setTime ( date ) ;

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

if (day==1) days++;

calendar.add ( Calendar.DATE, days ) ; //.MONTH o .YEAR...

return dateFormat.format ( calendar.getTime ( ) ) ;

} catch ( Exception e ) {

return "error";

}

Regards,

Matias

ps: please award points if helpful.

Edited by: Matias Denker on Jan 2, 2008 11:27 AM

former_member194786
Active Contributor
0 Kudos

Hi Kamran,

Try using the date after function of the date functions in graphical editor. Might help. I have never used it though.

Thanks and Regards,

Sanjeev.