Solved

so how to change date in the form of  dd/MM/yyyy or any other way to do this?

Posted on 2006-10-27
8
188 Views
Last Modified: 2010-03-31
in the UI, Date is coming as  01OCT06 but in the DB, date is inserted as 3/18/2004.

so how to change date in the form of  dd/MM/yyyy or any other way to do this?

HOW TO CONSTRUCT query like "EMPDATE BETWEEN "+UIDATE+"  AND " +UIDATE;
0
Comment
Question by:chaitu chaitu
  • 4
  • 2
  • 2
8 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 17819227
Use a PreparedStatement and setDate
0
 
LVL 86

Assisted Solution

by:CEHJ
CEHJ earned 250 total points
ID: 17819241
Use a DateFormat to get the input right

DateFormat df = new SimpleDateFormat("ddMMMyy");
Date d = df.parse("01OCT06 ");
0
 
LVL 20

Author Comment

by:chaitu chaitu
ID: 17819264
date should be constructed as

 "EMPDATE BETWEEN 3/18/2004  AND 3/30/2004";
0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
LVL 86

Expert Comment

by:CEHJ
ID: 17819321
String sql = "...................EMPDATE BETWEEN ?  AND ?";
PreparedStatement ps = conn.prepareStatement(sql);
ps.setDate(1, d1);
ps.setDate(2, d2);
ResultSet rs = ps.executeQuery();
0
 
LVL 92

Accepted Solution

by:
objects earned 250 total points
ID: 17824222
what type is empdate in database?

if you wanr to use a PrepardedStatement then you'll needto convert to java.sql.Date

String date = "01OCT06";
DateFormat df = new SimpleDateFormat("ddMMMyy");
java.sql.Date d = new java.sql.Date(df.parse(date).getTime());
String sql = "select ................... where EMPDATE =?";
PreparedStatement ps = conn.prepareStatement(sql);
ps.setDate(1, d);
ResultSet rs = ps.executeQuery();

then to format the date from resulkt set use:

DateFormat outputFormat = new SimpleDateFormat("MM/dd/yyyy");
String result = outputFormat.format(rs.getDate("EMPDATE"));
0
 
LVL 20

Author Comment

by:chaitu chaitu
ID: 17824559
what type is empdate in database?
DATE
0
 
LVL 92

Expert Comment

by:objects
ID: 17824613
then what i posted above should work. let me know if u have any probs.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 17828181
:-)
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
javap bin 2 40
map related example 6 55
arguments to jar 5 33
Configure a Bean in an XML file 4 42
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…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
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.

792 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