W
wkq2000
Unregistered / Unconfirmed
GUEST, unregistred user!
环境: 后台MS SQL Server, BDE引擎
如下代码:
var
F: TDateTime;
begin
F := Now;
Query1.Append;
Query1.FieldByName('OPTIME').AsDateTime:= F;
ListBox1.Items.Add('Now: ' + FormatDateTime('YYYYMMDD HH:MM:SS.ZZZ', F) + ' -- '
+ 'QueryTime: ' + FormatDateTime('YYYYMMDD HH:MM:SS.ZZZ', Query1.FieldByName('OPTIME').AsDateTime));
end;
实验发现, 在数据集中的'OPTIME'的毫秒级时间总是会将F自动"四舍五入"成'0'.'3'.'6'.'9'四种情况,例如ListBox中:
"Now: 20020909 10:15:17.807 -- QueryTime: 20020909 10:15:17.806"
接着将数据提交:
if not DataBase1.InTransaction then
DataBase1.StartTransaction;
try
Query1.ApplyUpdates;
DataBase1.Commit;
except
DataBase1.Rollback;
end;
实际上后台数据库所保存的数据的'OPTIME'字段的值为:'2002-09-09 10:15:17.803'
通过SQL Monitor监视的SQL语句发现:提交语句是用参数将字段的值代入Insert语句中,而以外的是
58 10:16:45 SQL Data In: MSSQL - Param = 4, Name = , Type = fldTIMESTAMP, Precision = 0, Scale = 0, Data = 9/9/2002 10:15:17:803000000
这样一来,实际存储的数据和原本赋予的值相差很远了,从'20020909 10:15:17.807'变成'2002-09-09 10:15:17.803'
再提供几组测试数据:
F(Now) Query1.FieldByName('OPTIME').AsDateTime 后台数据
2002-09-09 10:41:26.966 2002-09-09 10:41:26.963 2002-09-09 10:41:26.960
2002-09-09 10:41:27.421 2002-09-09 10:41:27.420 2002-09-09 10:41:27.420
....
请教各位关于这种时间上的差异怎么解决????
如下代码:
var
F: TDateTime;
begin
F := Now;
Query1.Append;
Query1.FieldByName('OPTIME').AsDateTime:= F;
ListBox1.Items.Add('Now: ' + FormatDateTime('YYYYMMDD HH:MM:SS.ZZZ', F) + ' -- '
+ 'QueryTime: ' + FormatDateTime('YYYYMMDD HH:MM:SS.ZZZ', Query1.FieldByName('OPTIME').AsDateTime));
end;
实验发现, 在数据集中的'OPTIME'的毫秒级时间总是会将F自动"四舍五入"成'0'.'3'.'6'.'9'四种情况,例如ListBox中:
"Now: 20020909 10:15:17.807 -- QueryTime: 20020909 10:15:17.806"
接着将数据提交:
if not DataBase1.InTransaction then
DataBase1.StartTransaction;
try
Query1.ApplyUpdates;
DataBase1.Commit;
except
DataBase1.Rollback;
end;
实际上后台数据库所保存的数据的'OPTIME'字段的值为:'2002-09-09 10:15:17.803'
通过SQL Monitor监视的SQL语句发现:提交语句是用参数将字段的值代入Insert语句中,而以外的是
58 10:16:45 SQL Data In: MSSQL - Param = 4, Name = , Type = fldTIMESTAMP, Precision = 0, Scale = 0, Data = 9/9/2002 10:15:17:803000000
这样一来,实际存储的数据和原本赋予的值相差很远了,从'20020909 10:15:17.807'变成'2002-09-09 10:15:17.803'
再提供几组测试数据:
F(Now) Query1.FieldByName('OPTIME').AsDateTime 后台数据
2002-09-09 10:41:26.966 2002-09-09 10:41:26.963 2002-09-09 10:41:26.960
2002-09-09 10:41:27.421 2002-09-09 10:41:27.420 2002-09-09 10:41:27.420
....
请教各位关于这种时间上的差异怎么解决????