?
Solved

Displaying Date from MsAccess to a general format

Posted on 2000-03-27
2
Medium Priority
?
221 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 100 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
Suggested Courses
Course of the Month10 days, 16 hours left to enroll

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