• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 196
  • Last Modified:

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

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
chaitu chaitu
Asked:
chaitu chaitu
  • 4
  • 2
  • 2
2 Solutions
 
CEHJCommented:
Use a PreparedStatement and setDate
0
 
CEHJCommented:
Use a DateFormat to get the input right

DateFormat df = new SimpleDateFormat("ddMMMyy");
Date d = df.parse("01OCT06 ");
0
 
chaitu chaituAuthor Commented:
date should be constructed as

 "EMPDATE BETWEEN 3/18/2004  AND 3/30/2004";
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
CEHJCommented:
String sql = "...................EMPDATE BETWEEN ?  AND ?";
PreparedStatement ps = conn.prepareStatement(sql);
ps.setDate(1, d1);
ps.setDate(2, d2);
ResultSet rs = ps.executeQuery();
0
 
objectsCommented:
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
 
chaitu chaituAuthor Commented:
what type is empdate in database?
DATE
0
 
objectsCommented:
then what i posted above should work. let me know if u have any probs.
0
 
CEHJCommented:
:-)
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 4
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now