• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Converting Textfield to Date field

 
RaviSingh Kumar
Ranch Hand
Posts: 52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i am converting JTextField value to Date datatype using SimpleDateFormatter("dd/mm/yyyy"). The output is given as:

Sun Jan 22 00:10:00 GMT+05:30 2006

But while inserting data into database, i want that the date should be in this form '22-Jan-2006'.

Can anyone give me suggestion to this.

Thanks in advance
 
Brian Cole
Author
Ranch Hand
Posts: 886
1
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by RaviSingh Kumar:
i am converting JTextField value to Date datatype using SimpleDateFormatter("dd/mm/yyyy"). The output is given as:

Sun Jan 22 00:10:00 GMT+05:30 2006

But while inserting data into database, i want that the date should be in this form '22-Jan-2006'.

Can anyone give me suggestion to this.


For input, it's probably easiest to use JFormattedTextField:

Presuming you're using JDBC to access the database, it's probably easiest to use a PreparedStatement and let the JDBC driver worry about conversion:

[edit: "dd/mm/yyyy" -> "dd/MM/yyyy" ('mm' is minute-in-hour, not month-in-year)]
[ February 12, 2008: Message edited by: Brian Cole ]
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic