Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


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
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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

In my humble opinion (IMHO), TouchDown from Symantec is the best in class for this type of application, but Symantec has end-of-lifed it and although one can keep using it, it will no longer be supported or upgraded.  Time to look for alternatives t…
How do you create a user-centered user experience on your website? And what are some things you should consider in the process?
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…

571 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