Forums Register Login

Convert String to sql.Date

+Pie Number of slices to send: Send
Hi,

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


thank you for your help,
Ajay
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
Hi Ulf,

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.

Thank you for help and reply
Ajay
+Pie Number of slices to send: Send
 

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?
+Pie Number of slices to send: Send
Hi Ajay,

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?

Your help is greatly appreciated.

Thank you!
+Pie Number of slices to send: Send
java.sql.Date is a type for dates only, just as java.sql.Time is a type for times only. To combine them use java.sql.Timestamp.
Nothing? Or something? Like this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 56041 times.
Similar Threads
string convert in to Sql ate format
sql.date trouble
Converting String to util.Date and then sql.Date
Converting string to util.date & then sql.date to query a table
util.Date to sql.Date
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 16, 2024 03:55:23.