• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Date Conversion

 
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a question that I'm hoping there is an easy answer to..... I don't want the solution to be too messy, ie string manipulation if i can help it.

I am querying the user to enter a date, in the format dd-mmm-yyyy, in other words 12-Dec-2004(This is a UK application), however in order for me to convert the date to a timestamp for use with SQL Server, it must be in the format yyyy-mm-dd. Is there an existing class that handles conversions of this sort or am i looking at writing a method to do it?
Thanks alot
 
Bartender
Posts: 9615
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
java.text.SimpleDateFormat
Please avoid the common mistake and use 2 different instances. One to parse the incoming data and one to format the outgoing data.
 
author
Posts: 154
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It strikes me that you may be going the wrong way about this.
If you're using JDBC to run a query on the database, it would be safer to use a PreparedStatement, and then use the setTimestamp() method to set parameters in your SQL. This takes care of all the necessary conversions behind the scenes.
Generating SQL strings directly should generally be avoided, if possible, because if you're not careful it can leave you open to SQL insertion attacks.
David Peterson
 
Here. Have a potato. I grew it in my armpit. And from my other armpit, this tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic