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
189 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 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
Independent Software Vendors: 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 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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
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…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

697 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