on 12-20-2006 7:44 PM
I want to sybstract 1 day from the given DATE.
My userdefined function has only 1 argument which receives the given Date.
argument name is " a "
Imports :
java.util.Date;java.text.*;java.util.Calendar;java.util.GregorianCalendar;
public String dateTrans(String a,Container container){
String DATE_FORMAT = "yyyyMMdd";
java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat(DATE_FORMAT);
Calendar c1 = Calendar.getInstance();
c1.set(Calendar.YEAR,2006);
c1.set(Calendar.MONTH,6);
c1.set(Calendar.DATE,7);
c1.add(Calendar.DATE, -1);
String s = sdf.format(c1.getTime());
return s;
}
My target field receiving the value " 20060706 "
which was my defaut date - 1 day.
Its not taking the value which I'm passing as an argument.
can someone please look into it, as I'm not that good at "Java Programming "
Thanks
sagar
my source date format is " yyyyMMdd ".
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Try this:
import java.util.Date;
import java.util.Calendar;
import java.text.SimpleDateFormat;
import java.text.DateFormat;
DateFormat inputFormat = new SimpleDateFormat("yyyyMMdd");
DateFormat outputFormat = new SimpleDateFormat("yyyyMMdd");
//String da = myformat.format(new Date());
Date ed = new Date();
try {
Date sd = inputFormat.parse(a);
a = inputFormat.format(new Date());
Calendar cal = Calendar.getInstance();
cal.setTime(sd);
int num = -1;
cal.add(Calendar.DATE, num);
ed = cal.getTime();
return outputFormat.format(ed).toString();
} catch (Exception e){
return "";
}
Regards,
Sandro
Hi,
First you have to set the date. Please check this method:
void <b>setTime(Date date)</b>
http://java.sun.com/j2se/1.5.0/docs/api/java/util/Calendar.html
Regards,
Wojciech
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 | |
24 | |
11 | |
9 | |
7 | |
6 | |
5 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.