This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes JDBC 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 Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Databases » JDBC
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: 60752
    
  65

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
internet detective
Marshal

Joined: May 26, 2003
Posts: 30068
    
149

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
 
jQuery in Action, 2nd edition
 
subject: date format with MS Access database
 
Similar Threads
Unparseable Date
SimpleDateFormat question
unable to retrieve timestamp in my servlet
unable to retrieve timestamp in my servlet
problem while insert date data in mysql