File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC and the fly likes date format with MS Access database Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Databases » JDBC
Reply Bookmark "date format with MS Access database " Watch "date format with MS Access database " New topic
Author

date format with MS Access database

Peter Primrose
Ranch Hand

Joined: Sep 10, 2004
Posts: 755
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

Joined: Jan 10, 2002
Posts: 56192
    
  13

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.


[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
Peter Primrose
Ranch Hand

Joined: Sep 10, 2004
Posts: 755
as a string
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 26192
    
  66

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.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: date format with MS Access database
 
Similar Threads
SimpleDateFormat question
unable to retrieve timestamp in my servlet
Unparseable Date
problem while insert date data in mysql
unable to retrieve timestamp in my servlet