Switch to full style
Java2 codes,problems ,discussions and solutions are here
Post a reply

String to sql.Date

Wed Oct 22, 2008 1:17 am

In my application I am getting one String variable which holds date in
yyyy-mm-dd hh:mm:ss format. It is a String type and i would like to
convert it in sql.Date. TO convert in sql.Date type i am doing the
following:

1) I am getting value in format of yyyy-mm-dd hh:mm:ss, example
2008-03-19 19:44:58
2) i am trying like:

// stringDate is holding value 2008-03-19 19:44:58

DateFormat formater = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
java.util.Date parsedUtilDate = formater.parse(stringDate);
java.sql.Date sqltDate= new java.sql.Date(parsedUtilDate.getTime());

when i convert String date i get in parsedUtilDate: Wed Mar 19
19:44:58 IST 2008
and sqltDate is having value 2008-03-19

could you please help me to get date in same format in sqltDate (as it
is stringDate), 2008-03-19 19:44:58



Re: String to sql.Date

Wed Oct 22, 2008 1:18 am

java.sql.Date.toString() only format to yyyy-mm-dd
Use java.sql.Timestamp instead.

Post a reply
  Related Posts  to : String to sql.Date
 Convert String to Date     -  
 Want start and end date of a month from current date     -  
 Formatting a Date with date()     -  
 Splitting a String Based on a Found String     -  
 check if string ends with specific sub-string in php     -  
 recursive string reversal- reverse string     -  
 check if string start with a specific sub-string in PHP     -  
 String token for string split     -  
 get next date by next day     -  
 Date in Java     -  

Topic Tags

Java Strings