Convertion date format in jsp

Posted on 2003-03-25
Medium Priority
Last Modified: 2012-06-27
My system use Apache Tomcat 4.1 and MySQL as a server.MySQL also keep the data that had been added and deleted.In database,date are save in yy/mm/dd.But in my login form,user has to input the date in dd/mm/yy format by the date given in the table form.The user has to choose the date from the calendar form in login form and the date will display in the text box.
The coding for this condition is shown as below:
 <script language="Javascript" src="calendar.js"></script>
             <INPUT name="tkhMohon"> <a href="javascript: void(0);" onclick="return getCalendar(document.addPermohonan.tkhMohon);"><img src="calendar.png" border="0" /></a>

tkhMohon = date

For login form,i use jsp as a language and the date format is dd/mm/yy.But when date has been added in the form,the database can't read the date format as dd/mm/yy.The problem occured is show as below.

In database:

If we input the date as 25/03/2003.The data will save as 2005/03/20.So, how to make the database read the data in the right condition as dd/mm/yy?
Thank you.
Question by:Wanie
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
LVL 19

Accepted Solution

cheekycj earned 100 total points
ID: 8211102
create a Date object from the original date.
String dateFormfieldValue = request.getParameter("tkhMohon");
if (dateFormfieldValue != null) {
java.text.DateFormat formatter = new java.text.SimpleDateFormat("dd/MM/yy");
java.util.Date enteredDate = (java.util.Date)formatter.parse(dateFormfieldValue);
//to insert into the DB use a prepared statement
  Connection conn;
  PreparedStatement ps;


            conn = DriverManager.getConnection("jdbc:mysql://localhost/dbname","username","password");
            ps = conn.prepareStatement("insert into yourtable (datecolumn) values (?)");
            ps.setDate(1, (java.sql.Date) enteredDate);
   } else {
value was not entered
<% } %>

LVL 35

Expert Comment

ID: 10060855
 *This is a dublicate question but I think cheekycj is worth the points*

No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

- Points to cheekycj

Please leave any comments here within the next seven days.


EE Cleanup Volunteer

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

This article lists the top 5 free OST to PST Converter Tools. These tools save a lot of time for users when they want to convert OST to PST after their exchange server is no longer available or some other critical issue with exchange server or impor…
In the absence of a fully-fledged GPO Management product like AGPM, the script in this article will provide you with a simple way to watch the domain (or a select OU) for GPOs changes and automatically take backups when policies are added, removed o…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

770 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