• 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

Converting Textfield to Date field

 
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Author
Posts: 986
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
My first bit of advice is that if you are going to be a mime, you shouldn't talk. Even the tiny ad is nodding:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic