Solved

Displaying Date from MsAccess to a general format

Posted on 2000-03-27
2
214 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
Comment Utility
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
Comment Utility
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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

743 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now