on 10-27-2008 10:52 PM
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
Thanks for your answers, both were really helpful, I already coded my user function.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
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 | |
10 | |
10 | |
7 | |
6 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.