cancel
Showing results for 
Search instead for 
Did you mean: 

Date format

Former Member
0 Kudos

Hi All,

I want to less one day from current date send it to the target. How to less one day from Current date.

eg :27/12/2010 and the required output should be 26/12/2010

Regards,

Eswar.

Accepted Solutions (1)

Accepted Solutions (1)

RKothari
Contributor
0 Kudos

Hi,

You can use the below mentioned UDF code:

import java.util.*;
import java.text.*;
int date2 = (-1);
Date date = null;
final DateFormat df = new SimpleDateFormat(""yyyyMMdd"");
try {
Date date1  = new Date();
final String date1String = """" + a;
 
date = df.parse(date1String);
} catch (ParseException pe) {
pe.printStackTrace();
}
final GregorianCalendar cal = new GregorianCalendar();
cal.setTime(date);
cal.add(Calendar.DAY_OF_YEAR, date2);
final SimpleDateFormat dateFormat = new SimpleDateFormat(""yyyyMMdd"");
final String strDate = dateFormat.format(cal.getTime());
return strDate;

Answers (3)

Answers (3)

former_member518917
Participant
0 Kudos

For this you have to write a UDF

// import java.text.*

import java.util.Calendar.*

public String getPrevDate(String inputDate, Container container) throws StreamTransformationException{

AbstractTrace trace = container.getTrace();

String PrevDateStr ="";

try {

DateFormat dateFormat = new SimpleDateFormat("dd/mm/yyyy");

Date myDate = dateFormat.parse(inputDate);

Calendar calendar = Calendar.getInstance();

calendar.setTime(myDate);

calendar.add(Calendar.DAY_OF_YEAR, -1);

Date prevDate = calendar.getTime();

PrevDateStr = dateFormat.format(prevDate);

trace.addInfo("PrevDateStr :"+PrevDateStr);

} catch (ParseException e){

trace.addInfo("Exception :"+e);

}

return PrevDateStr;

-


Hope this help

former_member218672
Active Contributor
0 Kudos

Hi,

If you are doing this using Java, you can do this easily using java Calender. Below is a code sample -

DateFormat dateFormat = new SimpleDateFormat("dd/mm/yyyy");

Date myDate = dateFormat.parse(dateString);

Calendar calendar = Calendar.getInstance();

calendar.setTime(myDate);

calendar.add(Calendar.DAY_OF_YEAR, -1);

// Use the date formatter to produce a formatted date string

Date previousDate = calendar.getTime();

String result = dateFormat.format(previousDate);

also, you'll get similar code help from help.sap.

hope it helps....

Regards,

Sen

Former Member
0 Kudos

Hi,

Use Beforedate function and map to the target field. This would be better, if you would liek to get the server before date.

Else if you wish to get the previous date to the provided date, then it would be better to write a UDF.

Thanks,