We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you a podcast all about Citrix Workspace, moving to the cloud, and analytics & intelligence. Episode 2 coming soon!Listen Now

x

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

chaitu chaitu
on
Medium Priority
216 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;
Comment
Watch Question

CERTIFIED EXPERT
Top Expert 2016

Commented:
Use a PreparedStatement and setDate
CERTIFIED EXPERT
Top Expert 2016
Commented:
Use a DateFormat to get the input right

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

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

Author

Commented:
date should be constructed as

 "EMPDATE BETWEEN 3/18/2004  AND 3/30/2004";
CERTIFIED EXPERT
Top Expert 2016

Commented:
String sql = "...................EMPDATE BETWEEN ?  AND ?";
PreparedStatement ps = conn.prepareStatement(sql);
ps.setDate(1, d1);
ps.setDate(2, d2);
ResultSet rs = ps.executeQuery();
Java Developer
CERTIFIED EXPERT
Top Expert 2010
Commented:
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"));

Author

Commented:
what type is empdate in database?
DATE
Mick BarryJava Developer
CERTIFIED EXPERT
Top Expert 2010

Commented:
then what i posted above should work. let me know if u have any probs.
CERTIFIED EXPERT
Top Expert 2016

Commented:
:-)
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.