cancel
Showing results for 
Search instead for 
Did you mean: 

Reg: Converting string to SQL date

Former Member
0 Kudos

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();

}

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

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

Answers (3)

Answers (3)

Former Member
0 Kudos

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

NarendraChandel
Contributor
0 Kudos

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

Former Member
0 Kudos

Hi,

Please make the below change to your code.

 java.util.Date personal_DOB=null; 

Hope it solves your issue.

Jithin