Win a copy of Java Mock Exams (software) this week in the Programmer Certification (OCPJP) forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

date format with MS Access database

 
Peter Primrose
Ranch Hand
Posts: 755
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is something that drives me nuts:

I am using my jdbc with MSdatabase. Everything works GREAT except the date's format.

I am using the DD-MMM-YY format (e.g., 13-Oct-04 ) and the database saves it correctly (I initially set it up this way [data Type = Date/Time and format as above]).

When I input a date and look at the table I can see that the format is saved as I wanted BUT when I retrieve the information, the format given is: 2004-10-13 00:00:00

I had to write a method to correct this format (eliminate the 00:00:00) but I feel it's very inefficient. I looked at the MSdb date type for date only - nothing.

Anyone?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65658
129
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How are you retrieving the info? As a String? As a java.sql.Date? If the latter, you can format it anyway you want to.
 
Peter Primrose
Ranch Hand
Posts: 755
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
as a string
 
Jeanne Boyarsky
author & internet detective
Sheriff
Posts: 35976
422
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Peter,
As Bear was getting at, use the getDate() method. This will return a Date object which you can then format using DateFormat. You just specify a formatter with the format of your choice.
 
What are you doing? You are supposed to be reading this tiny ad!
the new thread boost feature brings a LOT of attention to your favorite threads
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!