cancel
Showing results for 
Search instead for 
Did you mean: 

Incorrect Date Calculation in XI3.0 SP15

Former Member
0 Kudos

I have noticed an error on an interface that was supposed to be fixed before my colleague went on leave, however, it remains incorrect.

We are running XI3.0 SP15

Anyway, I have two fields in the mapping that are to be added together to become a date. Date + days = new date.

However, the code is not behaving properly

We are using a user defined function to calculate the date, but 28/12/2006 + 28 should equal 25/01/2007, the system is calculating 28/12/2006 + 28 = 25/01/2006

The user defined code is as follows:

imports java.util.Date;java.util.Calendar;java.text.ParseException;java.text.SimpleDateFormat;java.util.GregorianCalendar;

public String AddDaysToADate(String a,String b,Container container){
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
Date d = null;
try {d = sdf.parse(a);} catch (ParseException e) {}
GregorianCalendar gc = new GregorianCalendar();
gc.setTime(d);
gc.roll(Calendar.DAY_OF_YEAR, Integer.parseInt(b));
Date end = gc.getTime();
return sdf.format(end);
}

Not sure if anyone can help me....

Accepted Solutions (0)

Answers (4)

Answers (4)

Former Member
0 Kudos

Hi Barry,

Gud to know that u hv achieved. My idea is we must utilize the existing functionality instead of going for UDF's, so i prefer to go for mapping.

regards

Former Member
0 Kudos

Hi vijaya,

How do you solve below functionality using std.subtract functions.

Field_A (20071001) - Constant (19000000) = Result (1071001)

The Result should be 1071001.

Regards,

Naveen Chamala

Former Member
0 Kudos

hi Barry,

u can achieve this with message mappping like this:

1) Date Field or Current Date (yyyymmdd) ex:-20070105 (date)

2) Add a constant value ex:- 5 (days)

3) Transform the date field ex:- dd/mm/yyyy or the way u want

Result u wl get like : 10/01/2007.

its one option, i tested it and its working.

regards

Former Member
0 Kudos

Hi Barry N Forum,

I am extremely sorry, my logic is wrong.

regards

Former Member
0 Kudos

Vijaya

Do not apologise...

I have the answer though...

Sometimes just writing it out makes something click into place...

New code:

SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
Date d = null;
try {d = sdf.parse(a);} catch (ParseException e) {}
GregorianCalendar gc = new GregorianCalendar();
gc.setTime(d);
gc.add(Calendar.DATE, Integer.parseInt(b));
Date end = gc.getTime();
return sdf.format(end);

Resolved!

This was the "iffy bit of code"

gc.roll(Calendar.DAY_OF_YEAR, Integer.parseInt(b));

Roll - Adds or subtracts (up/down) a single unit of time on the given time field without changing larger fields.

Add - Adds the specified (signed) amount of time to the given time field, based on the calendar's rules.

Former Member
0 Kudos

Hi Barry,

y dont u try graphical mapping using date function and constant like

date --> constant --> add --> New date

regards