Getting Date in the form in JSP
Hi,
I am working on a form created in JSP that gets the date from the user, just in case the user wants to modify the date (default is current date), i wish to provide an option for that. Is there any other way apart from using list boxes asking for day,month and year?
My doubt is about the part - alternate for listboxes with separate options for day, month and year.
Thanks and Regards,
Reshma
Message was edited by:
ReshmaCB
[473 byte] By [
ReshmaCBa] at [2007-11-27 5:21:04]

# 1
Other way is to let the user manually enter the date in desired format, e.g. yyyy-MM-dd, and use SimpleDateFormat to convert between String and Date.
Date date = new Date(); // Today's date.
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
String dateString = sdf.format(date); // 2007-05-24
And the reversed way:String dateString = "2007-05-24";
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
Date date = sdf.parse(dateString); // Thu May 24 00:00:00 [zone] 2007
Check the [url=http://java.sun.com/j2se/1.5.0/docs/api/java/text/SimpleDateFormat.html]SimpleDateFormat API[/url] for several date format patterns.
# 5
Hi,
The problem is:
i used the following code
java.util.Date dtDate = new java.util.Date(2007,03,03);
java.sql.PreparedStatement stmt = con.prepareStatement("UPDATE MkgDetails SET ExamDateGiven = ? WHERE databaseNo = ?");
stmt.setDate(1,new java.sql.Date(dtDate.getTime()));
.................................
..............................
No compilation errors but ,
1. The date whcih is added to the database is 4/3/3907.
2. How can i replace this constant date to a variable which accepts a date from the user in a textbox?
like what do i do with the strDate = request.getParameter("text"+i);
where the text box was a dynamically generated JSP stmt.
Hope i am clear.
Regards,
Reshma