• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

VERY URGENT Please help me

 
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I have a project I use locales in that project to format the dates. I must use mm.dd.yyyy pattern. I use MSSQL server. I get the dates in dd.mm.yyyy format. There is not any problem when I get this and format this.
But I have a problem when I try to insert or update dates. Server excepts dd.mm.yyyy format. and end users enters the dates in mm.dd.yyyy format I used the following structure in my JSP page
I want to convert mm.dd.yyyy format to dd.mm.yyyy format. I get the start_date as a parameter of JSP page
----------------------
Locale currentLocale = new java.util.Locale("en", "US");
DateFormat currentDateFormatter = java.text.DateFormat.getDateInstance(java.text.DateFormat.SHORT, currentLocale);
String start_date=request.getParameter("StartDate");
System.out.println(start_date);
SimpleDateFormat formatter = new SimpleDateFormat ("mm.dd.yyyy");
start_date = formatter.format(new java.util.Date(start_date));
start_date=currentDateFormatter.format(new java.util.Date(start_date));
----------------------
Thanks,
 
author
Posts: 3252
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dates, aren't they just lovely. It can be hard not to make an absolute mess of them...
When using dates in queries, inserts and other DML statements, I religiously stick to PreparedStatements. They're more efficient anyway as they can be cached. And you can just call PreparedStatement.setDate() without worrying about date formats at all. If you must, really really must, generate your own string representation for the date, use a java.sql.Date to do it for you. It will generate a SQL-92 standard date representation. But really, use a PreparedStatement.
- Peter
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic