Connecting Tech Pros Worldwide Forums | Help | Site Map

Date conversion problem

MrMancunian's Avatar
Expert
 
Join Date: Jul 2008
Location: Utrecht, The Netherlands
Posts: 283
#1: Jul 24 '08
Hi,

I'm trying to insert some data in a table in SQL Server 2005, including a date. When I insert 29-07-2008 in the datetime field, it saves it as 25-7-1894 0:00:00. Can anyone tell me why it's doing that? The complete query is as follows:

Expand|Select|Wrap|Line Numbers
  1. INSERT INTO tblBCelLymfomen (BepalingID, BCelLymfomenDatumUitslag, BCelLymfomenKwaliteitBepaling, BCelLymfomenKwaliteitDNA, BCelLymfomenUitslag, BCelLymfomenConclusie, BCelLymfomenConclusie2, IgHAOnverdundGrootte, IgHBOnverdundGrootte, IgHCOnverdundGrootte, IgHDOnverdundGrootte, IgHEOnverdundGrootte, IgKappaAOnverdundGrootte, IgHAOnverdundBeschr, IgHBOnverdundBeschr, IgHCOnverdundBeschr, IgHDOnverdundBeschr, IgHEOnverdundBeschr, IgKappaAOnverdundBeschr, IgKappaBOnverdundGrootte, IgLambdaAOnverdundGrootte, IgKappaBOnverdundBeschr, IgLambdaAOnverdundBeschr) VALUES (1796, CONVERT(datetime, 29-07-2008, 120), '-', '-', 'Tests', '-', 'Tests', '1', '2', '3', '4', '5', '6', 'G', 'P', 'P(w)', 'R', 'R/P', 'Rw', '7', '8', 'Rw/P', 'D')
Thnx,

Steven

OuTCasT's Avatar
Needs Regular Fix
 
Join Date: Jan 2008
Location: South Africa
Posts: 361
#2: Jul 24 '08

re: Date conversion problem


are u using a DateTimePicker as the control
MrMancunian's Avatar
Expert
 
Join Date: Jul 2008
Location: Utrecht, The Netherlands
Posts: 283
#3: Jul 24 '08

re: Date conversion problem


Quote:

Originally Posted by OuTCasT

are u using a DateTimePicker as the control

No, the data is coming from an Access 2003 database. I tried using both the raw data from the database and a DateTime-datatype.

Steven
Delerna's Avatar
Expert
 
Join Date: Jan 2008
Location: Sydney
Posts: 790
#4: Jul 24 '08

re: Date conversion problem


Try changing this
Expand|Select|Wrap|Line Numbers
  1. CONVERT(datetime, 29-07-2008
  2.  
to this
Expand|Select|Wrap|Line Numbers
  1. CONVERT(datetime, '29-07-2008'
  2.  
or this
Expand|Select|Wrap|Line Numbers
  1. CONVERT(datetime, #29-07-2008#
  2.  
I'm thinking 29-07-2008 might be getting read as
29 minus 7 minus 2008 = -1986

25-7-1894 0:00:00 looks an awful lot like what happens when you save a number to a date field. The beginning of time according to microsoft is midnight on 01-01-1900
and i bet that date -1986 days (5.5 years) = 25-7-1894
MrMancunian's Avatar
Expert
 
Join Date: Jul 2008
Location: Utrecht, The Netherlands
Posts: 283
#5: Jul 29 '08

re: Date conversion problem


Quote:

Originally Posted by Delerna

Try changing this

Expand|Select|Wrap|Line Numbers
  1. CONVERT(datetime, 29-07-2008
  2.  
to this
Expand|Select|Wrap|Line Numbers
  1. CONVERT(datetime, '29-07-2008'
  2.  
or this
Expand|Select|Wrap|Line Numbers
  1. CONVERT(datetime, #29-07-2008#
  2.  
I'm thinking 29-07-2008 might be getting read as
29 minus 7 minus 2008 = -1986

25-7-1894 0:00:00 looks an awful lot like what happens when you save a number to a date field. The beginning of time according to microsoft is midnight on 01-01-1900
and i bet that date -1986 days (5.5 years) = 25-7-1894

The quotes worked. Thnx! :)
Reply