aspose file tools
The moose likes JDBC and Relational Databases and the fly likes date format with MS Access database Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of RabbitMQ in Depth this week in the Open Source forum!
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "date format with MS Access database " Watch "date format with MS Access database " New topic

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.

Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 62743

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.

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Peter Primrose
Ranch Hand

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

Joined: May 26, 2003
Posts: 32016

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.

[OCA 8 book] [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:
subject: date format with MS Access database