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:
[B]/ [/B] 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
sqltDate is a Date object - it has no formatting. If you want to format it, use a DateFormatter like formater, which already has the format you're looking for. Its format format can transform a Date to a String. But since stringDate already has that string value, I'm not sure why you'd want to do this.
Joined: Mar 16, 2008
Thanks for your early reply.
i need to insert sqltDate in database through hibernate. i want to convert as 2008-03-19 19:44:58 is converted to Wed Mar 19 19:44:58 IST 2008 in java.util.Date variable
As you mentioned Its format format can transform a Date to a String.
i want to convert string to java.sql.Date so sqltDate variable could hold the 2008-03-19 19:44:58 and it could be inserted in database field which has datatype Date.
Is there any way to convert string value 2008-03-19 19:44:58 to java.sql.Date.
Originally posted by ajay tickle: Is there any way to convert string value 2008-03-19 19:44:58 to java.sql.Date.
The code you posted with your original question already does that.
Don't be misled by what you see when you use System.out.println to display a java.util.Date or java.sql.Date object. What you see there is just for your convenience and has nothing to do with how Hibernate will use the object.
Are you having actual problems with Hibernate or is this just a problem that you think you have, so you haven't tried using it with Hibernate yet?
Have you eventually converted the string to sqltDate (as it is stringDate), 2008-03-19 19:44:58?
I am having the same problem (the sqlDate only has the date information, lost the time infor after conversion) as you had a while ago. If you were able to solve the problem, could you let me know how you did it?