This week's book giveaway is in the OCPJP forum. We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line! See this thread for details.
Hi, Folowing is my senario, 1) I am reading Form input text field 'Date' as String str1=request.getParameter("Date"); which accepts input in yyyymmdd format. eg: str1="20020422" 2) I want to store this Date into table with column type Date AssignedOn Date 3)I am using PrepareStatement to insert values into table. setDate(1,Datevar) problem here is Datevar must be sql.Date type 4)I am converting String to sql Date as Long l1=new Long(str1); long l2=l1.longValue(); Date d1= new Date(l2); System.out.println("long value:"+ l2); System.out.println("Date:"+ d1.toString()); First print prints:long value:4122002 Second prints : Date:1969-12-31 Why it is taking wired value? I even try by giving String in 'mmddyyyy' format it prints 1969-12-31. what's happening here? Please let me any one knows any other way to store Date value(which is from htnl form) in table. Thanks, padmashree [ April 22, 2002: Message edited by: padma patil ]
Padma The constructor for Date that takes a long as an argument creates a date based on the number of milliseconds since January 1 1970 at 00:00:00 not the date itself. To do what you are trying to do why ot just take the date you get and add the dashes (-) into it separate the yyyy-mm-dd and then just store it that way?