cancel
Showing results for 
Search instead for 
Did you mean: 

Handling date to ADD or Substract fixed # of days using standard function

Former Member
0 Kudos

Hi ,

Using the standard functions in XI, is it possible to add or subtract a fixed number of days from the date i get from the input file.

Like, from file I get the date as 25/06/2009.My output should be 05/07/2009 after adding 10 days .

can some one guide how to handle this.

Thanks,

Ven..

Accepted Solutions (0)

Answers (7)

Answers (7)

Former Member
0 Kudos

u can use 'SALP_CALC_DATE' which lets you add, delete days, weeks, months, quartes and years.

however there seems to be an error when youtry to subtract months; works as expected however when you add months or subtract days.

GabrielSagaya
Active Contributor
0 Kudos

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

public String myYDF(String a,Container container){

String notifyDates = a;

Calendar calendar = Calendar.getInstance ( ) ;

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

try {

Date date = dateFormat.parse ( notifyDates ) ;

calendar.setTime ( date ) ;

calendar.add ( Calendar.DATE, 10 ) ; // For subtraction use calendar.add ( Calendar.DATE, -10 )

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

} catch ( Exception e ) {

return "error";

}

}

0 Kudos

lOOK for

CALL FUNCTION '/SAPHT/DRM_CALC_DATE'

EXPORTING

date = l_datini

days = 1

months = 00

SIGN = '+'

years = 00

IMPORTING

calc_date = l_datini.

Best Regards.

Former Member
0 Kudos

Hi Ven,

Here is a UDF code,which takes date(format:yyyyMMdd) as input and does addition or subtraction operations based on <field 1> value,return the result date(format:yyyyMMdd) as string value.

public String GenerateDate(String date_input, String field1,Container container){

//Here "date_input" and "field1" are inputs for this UDF

int date = Integer.parseInt(date_input);

Calendar cal;

int day = date % 100;

int month = (date/100) % 100 - 1;

int year = date / 10000;

cal = Calendar.getInstance();

cal.set(year, month, day);

/implement addition or subtraction logic here as your needs/

if (field1 == "A")

cal.add(Calendar.DATE, 10);

else if(field == "B")

cal.add(Calendar.DATE, -5);

day = cal.get(Calendar.DATE);

month = cal.get(Calendar.MONTH)+ 1;

year = cal.get(Calendar.YEAR);

date = year * 10000 + month * 100 + day;

return (""+date);

}

You can use Standard Funtion DateTrans to convert date from your format to the format used in the UDF and vice versa.

Regards

Pravesh

former_member200962
Active Contributor
0 Kudos

Req not possible using standard functions.....Check this for adding a day:

Former Member
0 Kudos

Don't think any standard functions are available for this purpose.

However a UDF can suffice as discussed in this thread:

Regards,

Manjusha.

former_member181962
Active Contributor
0 Kudos

Hi ven,

Not sure if you can achieve this using standard functions.

YOu can try this Java Code in a UDF:

http://www.java-examples.com/add-or-substract-days-current-date-using-java-calendar

Regards,

Ravi Kanth Talagana