• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Date

 
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).]
 
mister krabs
Posts: 13974
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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);

 
satishind Reddy
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13974
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 1467
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13974
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That will make a difference. Glad that your problem is solved!
 
Consider Paul's rocket mass heater.
    Bookmark Topic Watch Topic
  • New Topic