cancel
Showing results for 
Search instead for 
Did you mean: 

Message Mapping Date Operations

Former Member
0 Kudos

Hello everybody,

I'm need to do some operations with dates sucha as adds, substractions so I can add and substract dates from others, is there standard fucntions for these, or myabe somebody had developed a java user function for this, thanks in advance.

Regards,

Julio Cesar

Accepted Solutions (0)

Answers (4)

Answers (4)

Former Member
0 Kudos

Thanks for your answers, both were really helpful, I already coded my user function.

justin_santhanam
Active Contributor
0 Kudos

Julio,

Let say the input date format which you are getting is 20081029(yyyyMMdd) format and if you want to subtract 2 days from it. Then the below code will give you 20081027 as the o/p.

Create simple UDF ,with two parameters as the input.

Parameter1 - inputDate

Parameter2 - days( For example, if you want to add two days then you need to pass 2, if you want to subtract two days then you need to pass -2)


int day = Integer.parseInt(days);
int y = Integer.parseInt(inputDate.substring(0,4));
int m= Integer.parseInt(inputDate.substring(4,6));
int d = Integer.parseInt(inputDate.substring(6,8));

GregorianCalendar  gc1 = new GregorianCalendar(y,m-1,d);
gc1.add( Calendar.DAY_OF_MONTH , day);

Calendar cal = Calendar.getInstance();

cal.setTime(gc1.getTime());

int y1 = cal.get(Calendar.YEAR);
int m1 = cal.get(Calendar.MONDAY)+1;
int d1 = cal.get(Calendar.DAY_OF_MONTH);

String dd=String.valueOf(d1);

String mm=String.valueOf(m1); 

String yy = String.valueOf(y1);
if(d1<10) dd = "0" + d1;

if(m1<10) mm = "0" +m1;

String sap_date = yy + mm + dd;

return sap_date;

Hope it helps!

raj.

Former Member
0 Kudos

Thanks, for your answer but I'm not too familiar with java code, do you have more information with maybe an example code but for operations with dates not only transformations, thanks for your answers.

Regards,

Julio

Former Member
0 Kudos

check this standard functions..scroll to find the category DATE.

http://help.sap.com/saphelp_nw04/helpdata/en/c8/98e7d5c1620642973565ea3dd319d1/frameset.htm

You might need to create new in functions for addtional functionality and that is pretty simple..

check here.

(How do I calculate the difference between two dates?)

http://joda-time.sourceforge.net/faq.html

Calculating the Difference Between Two Datetime Stamps

http://www.xmission.com/~goodhill/dates/deltaDates.html

Get difference in days

http://javaalmanac.com/egs/java.util/CompDates.html

http://www.exampledepot.com/egs/java.util/CompDates.html

Former Member
0 Kudos

Hi

to add and Subtract dates standard functions are not present. using UDF its very easy to do operations on dates.

Check this

Thanks

Gaurav