• Post Reply Bookmark Topic Watch Topic
  • New Topic

conversion of date from dd/mm/yyyy to yyyy/mm/dd  RSS feed

 
zaheer agadi
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi i m using my mysql database and using stored procedure for inserting values into db my problem is mysql only takes values in the format yyyy/mm/dd but i m inserting as dd/mm/yyyy fro which i m using a third party calnedar how do i insert the date
thnx
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, date is a date, no matter what is the format. Date should be inserted as date. The data type for a date should be a date. Formatting stuff can be handled in code. You can use SimpleDateFormat class to format the date.

Now where is your problem? Please elaborate.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you're inserting to a database with a prepared statement you can pass a Date object as a parameter to the statement and JDBC will handle all that formatting stuff for you. Pretty slick.

If you're converting one string format to another string format you have a couple choices. One would be to use a SimpleDateFormat object to parse one string into a Date, and another SimpleDateFormat object to format the Date into another String. If you're going to do millions (really, many maillions) it might be faster to use substrings and concatenation.

Any of that sound like something you want to do? If you get stuck, post some not-quite-working code here and we'll help you get it going.
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Stan James:
If you're going to do millions (really, many maillions) it might be faster to use substrings and concatenation.


Or use a regular expression, which is probably somewhere in between, performancewise.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!