on 04-14-2009 7:29 AM
Hi,
How can i format a string date to SQL date. If i use the below code, its giving me error at the line personal_DOB=df.parse(DOB_Personal); that cannot convert util date to SQL date.
String DOB_Personal=record.getFieldValue(fields[2]).toString();
SimpleDateFormat df=new SimpleDateFormat("MM/dd/yyyy");
Date personal_DOB=null;
try {
personal_DOB=df.parse(DOB_Personal);
} catch (ParseException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
Hi Prasanthi,
use the below code.
String DOB_Personal="01/01/2009";
SimpleDateFormat df=new SimpleDateFormat("MM/dd/yyyy");
java.sql.Date personal_DOB=null;
try {
personal_DOB=new java.sql.Date(df.parse(DOB_Personal).getTime());
} catch (ParseException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
Regards,
Naga
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Exper,
Please check this Code...
String DOB_Personal="01/01/2009";
SimpleDateFormat df=new SimpleDateFormat("MM/dd/yyyy");
java.util.Date personal_DOB=null;
try {
personal_DOB=df.parse(DOB_Personal);
} catch (ParseException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
java.sql.Date sqldate=new java.sql.Date(personal_DOB.getTime());
System.out.println("re"+sqldate);
}
}
thanks
jati
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
hi,
String stringDate = "2009-04-14";
DateFormat formater = new SimpleDateFormat("yyyy-MM--dd");
java.util.Date parsedUtilDate = formater.parse(stringDate);
java.sql.Date sqltDate= new java.sql.Date(parsedUtilDate.getTime());
the above code will give you desired result.
regards
narendra
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
Please make the below change to your code.
java.util.Date personal_DOB=null;
Hope it solves your issue.
Jithin
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
95 | |
11 | |
10 | |
9 | |
9 | |
7 | |
6 | |
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.