Loss of Precision in DateTime

  • Thread starter Thread starter James
  • Start date Start date
J

James

For some reason when I pass a .net datetime value to a sqlType
DateTime to a smalldatetime in sql server, any value that happens to
fall at exactly midnight drops the time portion and only stores the
date? If I trace or do any sort of ToString() on any of the values
during the process in the app, it shows the time correctly, but when I
look in the db I only see the date...

DateTime lastDate = new DateTime(2004,1,1,0,0,0);

// Snip set db access obj
db.daLastAccessedDate = new SqlDateTime(lastDate);

// Snip set sp parameter
scmCmdToExecute.Parameters.Add(new SqlParameter("@LastAccessedDate",
SqlDbType.SmallDateTime, 4, ParameterDirection.Input, false, 16, 0,
"", DataRowVersion.Proposed, m_daLastAccessedDate));

// nothing fancy in sql server -- only a smalldatetime.

Has anyone else seen this? I really don't want to kludge this by
adding one minute or something...

James
 
James,
I think that your are just seeing a display feature in the database
where it doesn't show hh:mm:ss if they are all 0. My dates look the same
and they work just fine.

Ron Allen
 
How are you verifying it? ARe you looking in Enterprise manager or QA? If
it's showing in EM like that - it's not a problem - to verify it, do a
SELECT WhateverColumn from yourTable in QA and you should see the times as
well. If it's a varchar or something you could have a problem, but if it's
DateTime - it can't physically be stored without the Time although it may
'look' like it. If it's showing that way client side, again it may well
just be a formatting issue. So check the datasource(datatable or
datareader) and see that the actual value is before you check the contorl or
UI tool that's displaying it.

HTH,

Bill

--

W.G. Ryan, eMVP

Have an opinion on the effectiveness of Microsoft Embedded newsgroups?
Let Microsoft know!
https://www.windowsembeddedeval.com/community/newsgroups
 
You're right. When using the query pane in EM you don't see the time
at midnight... Through QA it is correct.

Thanks!
 
Back
Top