Board index » delphi » ADO eats milliseconds when assign it to parameters ?!

ADO eats milliseconds when assign it to parameters ?!

Hi everybody,
It looks like ADO eats milliseconds when assign it to parameters.
Please, put some light on the issue and how to work around.

var
    fDT: TDateTime;
begin
  // take date&time from first record from database, which is '2001-02-05
10:41:58.890
  ADODataSet1.Close;
  ADODataSet1.CommandText := 'select * from warehouses';
  ADODataSet1.Open;
  Edit1.text := FormatDateTime('yyyy/mm/dd hh:nn:ss.zzz',
ADODataSet1.FieldByName('WarehouseWhen').AsDateTime);  // displays time with
proper milliseconds
  fDT := ADODataSet1.FieldByName('WarehouseWhen').AsDateTime; // lets store
the time

  // try to find a record with this time
  ADODataSet1.Close;
  ADODataSet1.CommandText := 'select * from warehouses where WarehouseWhen
=:paramDT';
  ADODataSet1.Parameters.ParamValues['paramDT'] := fDT;  //'2001-02-05
10:41:58.890';
  ADODataSet1.Open;  // get empty result set !!
  // in this place SQL Profiler shows time sent as '20010205 10:41:59:000' -
rounded to seconds !!
end;

 

Re:ADO eats milliseconds when assign it to parameters ?!


Vlad,

This is a known problem with MSSQL.

datetime
Date and time data from January 1, 1753, to December 31, 9999,
to an accuracy of one three-hundredth second, or 3.33 milliseconds.
Values are rounded to increments of .000, .003, or .007 milliseconds.

HTH
--
Vassil Nazarov
IT Manager, Sofia Cable SA

Re:ADO eats milliseconds when assign it to parameters ?!


Vassil,

Sorry, it maight be I was not clear enough. Let me explane the issue.
I have in database a date&time, which is '2001-02-05 10:41:58.890' (is
already rounded. to .000).
Is is how QA shows it. I read the time into fDT: TDateTime of Delphi program
and
show it at screen - it is correct, with proper milliseconds (.890) and build
query with
parameter which is of TDataeTime type. After assigning fDT to the parameter
ADO sends to MS SQL  time 10:41:59.000 which is rounded to .010 milliseconds
?!

Regards,
Vlad

Re:ADO eats milliseconds when assign it to parameters ?!


Vassil,

Sorry, it maight be I was not clear enough. Let me explane the issue.
I have in database a date&time, which is '2001-02-05 10:41:58.890' (is
already rounded. to .000).
Is is how QA shows it. I read the time into fDT: TDateTime of Delphi program
and
show it at screen - it is correct, with proper milliseconds (.890) and build
query with
parameter which is of TDataeTime type. After assigning fDT to the parameter
ADO sends to MS SQL  time 10:41:59.000 which is rounded to .010 milliseconds
?!

Regards,
Vlad

Re:ADO eats milliseconds when assign it to parameters ?!


I see. I don't know why this rounding takes place but you
might be able to trace it down to the parameter binding
code in ADODB. Just a guess.

--
Vassil Nazarov
IT Manager, Sofia Cable SA

Re:ADO eats milliseconds when assign it to parameters ?!


Hi Vlad,

Quote
> ADO sends to MS SQL  time 10:41:59.000 which is rounded to .010

milliseconds

Maybe it has nothing to do but you might have a look:

http://support.microsoft.com/support/kb/articles/Q246/4/38.ASP

Thrse

Other Threads