wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes change data type from string to timestamp Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "change data type from string to timestamp" Watch "change data type from string to timestamp" New topic

change data type from string to timestamp

elli dian

Joined: May 18, 2006
Posts: 15
I wanto to change data type from string to timestamp,
but I get a not suitable value according format DD-MM-YYYY

My coding :
String fdate="02-05-2006";
SimpleDateFormat dateFormat = new SimpleDateFormat("DD-MM-yyyy");
java.util.Date parsedFDate = dateFormat.parse(fdate);
java.sql.Timestamp fdateabsence=new java.sql.Timestamp(parsedFDate.getTime());

I get result=2006-01-02 00:06:00.0

Please help me... so I get result according my fdate is=02-05-006 and data type will be timestamp
Shaan Shar
Ranch Hand

Joined: Dec 27, 2005
Posts: 1249

[ June 08, 2006: Message edited by: Ankur Sharma ]

The Best way to predict your future is to create it - Every great individual common man
elli dian

Joined: May 18, 2006
Posts: 15
I get still a false value: if I use format dd-MM-yyyy
the result is:2006-05-02, but I want to get a value:02-05-2006.
Please help me again?
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14074

Maybe you don't understand the difference between a Timestamp object and the string representation of a Timestamp object.

A Timestamp object contains a date and time. It does not have a specific format by itself. If you call toString() on a Timestamp, you might get a String that looks like "2006-01-02 00:06:00.0". The toString() method uses a default format, because it has to convert the date and time value into a String somehow. But again, the format itself is not a property of the Timestamp object.

If you want to convert the Timestamp object to a String with a specific format, you need to use the SimpleDateFormat.format(...) method, which allows you to specify a specific format.

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
I agree. Here's the link: http://aspose.com/file-tools
subject: change data type from string to timestamp
Similar Threads
How to change Date Format
convert data type string to timestamp
Date Confusion
inserting a date field
comparing date