aspose file tools*
The moose likes JDBC and the fly likes urgent please help Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "urgent please help" Watch "urgent please help" New topic
Author

urgent please help

john mattucci
Ranch Hand

Joined: Nov 03, 2000
Posts: 331
I have read all the posts and I havent really found an
answer to my question I was wondering the easist way to change
a Timestamp to the format mm/dd/yy eg i get 2001-10-01-00-00-00.... from timestamp what is an easy way to convert this to
10/01/01
Thank u for your time
------------------
Adam Hardy
Ranch Hand

Joined: Oct 09, 2001
Posts: 566
i'm not at my development pc so i haven't tested this but you said it's urgent, so try this: you can use all the java.util.Date methods because Timestamp extends Date.
Check out .toString()
http://java.sun.com/j2se/1.3/docs/api/java/util/Date.html#toString()

I have seen things you people would not believe, attack ships on fire off the shoulder of Orion, c-beams sparkling in the dark near the Tennhauser Gate. All these moments will be lost in time, like tears in the rain.
john mattucci
Ranch Hand

Joined: Nov 03, 2000
Posts: 331
this gives me a long string with too much info eg the day of the
week. I want a string in the form 10/28/01 and is there an easy way to get this from a Timestamp
------------------
shilpa kulkarni
Ranch Hand

Joined: Jun 07, 2000
Posts: 87
How about -
Timestamp t = ....
out.println(t.getMonth()+"/"+t.getDate()+"/"+t.getYear());
shilpa kulkarni
Ranch Hand

Joined: Jun 07, 2000
Posts: 87
How about -
Timestamp t = ....
out.println(t.getMonth()+"/"+t.getDate()+"/"+t.getYear());
shilpa kulkarni
Ranch Hand

Joined: Jun 07, 2000
Posts: 87
Originally posted by john mattucci:
this gives me a long string with too much info eg the day of the
week. I want a string in the form 10/28/01 and is there an easy way to get this from a Timestamp

How about -
Timestamp t = ....
out.println(t.getMonth()+"/"+t.getDate()+"/"+t.getYear());
shilpa kulkarni
Ranch Hand

Joined: Jun 07, 2000
Posts: 87
sorry for the repeated posts.
i tried it thrice because it refused to submit the reply the first time and then the next time too....
Adam Hardy
Ranch Hand

Joined: Oct 09, 2001
Posts: 566
how about

Toyin Sogeke
Greenhorn

Joined: Oct 08, 2001
Posts: 14
Hi,
You can use the java.util.StringTokenizer class as follows:
String sDate = "2001-10-11 00:00:00";
StringTokenizer sToken =
new StringTokenizer(sDate," ");
String datePart = sToken.nextToken();
sToken = new StringTokenizer(datePart,"-");
String yyyy = sToken.nextToken();
String mm = sToken.nextToken();
String dd = sToken.nextToken();
String yy = yyyy.substring(2,3);
StringBuffer sBuf = new StringBuffer( mm );
sBuf.append( "/" );
sBuf.append( dd );
sBuf.append( "/" );
sBuf.append( yy );
String mmddyy = sBuf.toString();
System.out.println( "Date: " + mmddyy );
This should print: 10/11/01
Hope the above code helps.
Cheers
Originally posted by john mattucci:
I have read all the posts and I havent really found an
answer to my question I was wondering the easist way to change
a Timestamp to the format mm/dd/yy eg i get 2001-10-01-00-00-00.... from timestamp what is an easy way to convert this to
10/01/01
Thank u for your time


homeboy
Shiv Sidhaarth
Ranch Hand

Joined: Aug 06, 2001
Posts: 119
If u r reading data from Oracle, u can use
to_char(datefield,'mm/dd/yy') while selecting columns in SQL statement.
Sankar
Ali Hassaan
Ranch Hand

Joined: May 16, 2001
Posts: 103
easiest way is to use to_date(date,"mm/dd/yyyy") in your sql query if you ar using oracle else in sqlserver CONVERT(char(50), date)..
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: urgent please help