Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

VERY URGENT Please help me

 
koray guclu
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • 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,
 
Peter den Haan
author
Ranch Hand
Posts: 3252
  • Mark post as helpful
  • send pies
  • 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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic