Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Displaying Date from MsAccess to a general format

Posted on 2000-03-27
2
Medium Priority
?
225 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

In this post we will learn different types of Android Layout and some basics of an Android App.
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
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:
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
Suggested Courses

610 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