?
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
Medium Priority
?
194 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
[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
  • 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 1000 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
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!

 
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 1000 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: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone 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

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…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
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…
This video teaches viewers about errors in exception handling.
Suggested Courses

649 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