on 01-05-2007 4:25 PM
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....
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Barry N Forum,
I am extremely sorry, my logic is wrong.
regards
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
Hi Barry,
y dont u try graphical mapping using date function and constant like
date --> constant --> add --> New date
regards
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
84 | |
10 | |
9 | |
8 | |
6 | |
6 | |
6 | |
5 | |
3 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.