Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Date Insert

 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
i want to know how i can convert a string into a date data type.
String date=request.getParameter("txtGraduationdate");
well in my backend i created the field as "date" data type.
So how will i be able to convert this.
Thanks and Regards,
vikram
 
Toyin Sogeke
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Sir,
You can use java class java.text.SimpleDateFormat
for your conversion as follows:
String stringDate = "2001-10-08";
SimpleDateFormat sdfInput =
new SimpleDateFormat( "yyyy-MM-dd" );
java.util.Date date = sdfInput.parse( stringDate );
Cheers
Originally posted by vikramnp:
Hi all,
i want to know how i can convert a string into a date data type.
String date=request.getParameter("txtGraduationdate");
well in my backend i created the field as "date" data type.
So how will i be able to convert this.
Thanks and Regards,
vikram

 
Dharmesh Chheda
Ranch Hand
Posts: 204
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello vikramp
the second way is that you can use the StringTokenizer class also
------------------
IBM Certified WebSphere Application Server V3.5 Specialist
 
Jamie Robertson
Ranch Hand
Posts: 1879
MySQL Database Suse
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is the way I convert it. I wish there was an easier way too!

Calendar.getTime() returns a Date object, then use getTime() on the Date object which returns milliseconds, which you can use in a Date constructor to create a new Date.
Jamie


[This message has been edited by Jamie Robertson (edited October 15, 2001).]
[This message has been edited by Jamie Robertson (edited October 15, 2001).]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic