Re: Date question




Jean-Francois Briere wrote:
Change it to a java.util.Date with java.text.SimpleDateFormat.
Then change it to a java.sql.Date:

String dateStr = "01-May-2006"
SimpleDateFormat sdf = new SimpleDateFormat("dd-MMMM-yyyy");
java.util.Date date = sdf.parse(dateStr);
java.sql.Date sqlDate = new java.sql.Date(date.getTime());


You really need to add the line:

sdf.setLenient();

to your solution. Otherwise, an input date like 39-May-2006 would be
accepted as valid and the code would return an SQL date of June 8th.

Of course, if you WANT that behaviour, don't add the setLenient()! I'd
prefer to reject a date that was obviously invalid rather than
interpret it into something valid by omitting the setLenient(). I doubt
that if the user entered 39-May-2006 he did it because he really MEANT
to enter 08-Jun-2006.


--
Rhino

.