Solved

Displaying Date from MsAccess to a general format

Posted on 2000-03-27
2
216 Views
Last Modified: 2012-06-27
I am getting a date from date field in MsAccess in a format of date and time(2000-01-12 12:03:45). Please write how to convert this to a display format of 01-Dec-2000.

Thank You,

Virendra
0
Comment
Question by:virendra032700
2 Comments
 
LVL 1

Expert Comment

by:dmaguillo
ID: 2663234
Hi virendra. Two months ago i wrote some java code for date fields accesing. JDBC-ODBC return date and time Access format like "java.sql.Timestamp". Here u have an example:

....
Object dateField = r.getObject(column);
....
int myDay  = Integer.parseInt(dateField.toString().substring(0,2));
int myMonth  = Integer.parseInt(dateField.toString().substring(3,5));
int myYear = Integer.parseInt(dateField.toString().substring(6,8));
         
// ie2k    
if (myYear < 30)
  myYear = myYear+2000;
else
  myYear = myYear+1900;
           
// Timestamp: yyyy-mm-dd hh:mm:ss.fffffffff
Timestamp myDate = Timestamp.valueOf(myYear+"-"+myMonth+"-"+myDay+" 00:00:00.000000000");
....

Bye... :)
0
 
LVL 19

Accepted Solution

by:
Jim Cakalic earned 25 total points
ID: 2675547
How about this:

import java.sql.Date;
import java.text.SimpleDateFormat;

public String formatDate(ResultSet rs, int column) {
    Date d = rs.getDate(column);
    SimpleDateFormat df = new SimpleDateFormat("dd-MMM-yyyy");
    return df.format(d);
}

This method returns a String containing the value formatted for display per your specification. The getDate() method is actually the JDBC recommended way to retrieve a DATE or TIMESTAMP column datatype value from a ResultSet.

Best regards,
Jim Cakalic
0

Featured Post

Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
simple java question 3 55
maven project error 5 55
Apps blocked by Java 9 79
use lov values 2 50
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question