Hi, I have a table in Microsoft SQL data base. In that table one field is a Date field. I am getting error while inserting record. I am giving code snippet please help me. what am I doing wrong here.
Thanks in advance. Regards Satish
[This message has been edited by Thomas Paul (edited December 07, 2000).]
Parsing the date in this way will simply remove the portions of the date that are not year-month-day but will not effect what is passed to the datatbase which is: 'Thu Dec 07 00:00:00 EST 2000'. You need to use the SimpleDateFormat to convert the Date object into a String. Try this: SimpleDateFormat fmt = new SimpleDateFormat ("MM/dd/yyyy"); String todate = fmt.format(date);
Hi Thomas, Thanks for reply. Still it is giving problem because in table level my date field data type is 'datetime'. SimpleDateFormat fmt = new SimpleDateFormat ("MM/dd/yyyy"); String todate = fmt.format(date); here 'todate' is string. and table level field data type is 'datetime'. so it is giving data mismatch error. please help to me. If i am not clear i can send code if u provide mail id. Thanks Satish
Thomas Paul
mister krabs
Ranch Hand
Joined: May 05, 2000
Posts: 13974
posted
0
All you have to do is figure out what is a valid String format that MS SQL will accept in a date/time field and then use SimpleDateFormat to reproduce that format.
Hi Reddy, The following is the code snippet which I use in My-SQL and Access. It may not be same in MS-SQL. You can try it. Otherwise please look into the documentation. In the foll. code the DOB(DateOfBirth) String has to be in yyyymmdd format regds maha anna
[This message has been edited by Thomas Paul (edited December 08, 2000).]
satishind Reddy
Ranch Hand
Joined: Oct 17, 2000
Posts: 33
posted
0
Hi paul, Paul i havn't noticed that 'MM' should be Caps otherwise it is taking minutes insted of month. Due to this i got error every time. Thanks for all your replies. Satish
Thomas Paul
mister krabs
Ranch Hand
Joined: May 05, 2000
Posts: 13974
posted
0
That will make a difference. Glad that your problem is solved!