• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

urgent please help

 
Ranch Hand
Posts: 331
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
------------------
 
Ranch Hand
Posts: 567
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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()
 
john mattucci
Ranch Hand
Posts: 331
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
------------------
 
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How about -
Timestamp t = ....
out.println(t.getMonth()+"/"+t.getDate()+"/"+t.getYear());
 
shilpa kulkarni
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How about -
Timestamp t = ....
out.println(t.getMonth()+"/"+t.getDate()+"/"+t.getYear());
 
shilpa kulkarni
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 87
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 567
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
how about

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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


 
Ranch Hand
Posts: 119
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If u r reading data from Oracle, u can use
to_char(datefield,'mm/dd/yy') while selecting columns in SQL statement.
Sankar
 
Ranch Hand
Posts: 103
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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)..
 
reply
    Bookmark Topic Watch Topic
  • New Topic