如何将TSQLTimeStamp转换为TDateTime

时间:2017-04-18 18:22:12

标签: delphi delphi-10-seattle

我在SQL Server 2008中有一个像这样的表:

CREATE TABLE B_INTERVENTION ( 
ID_BI INT IDENTITY PRIMARY KEY NOT NULL ,
Date_Creation DATE NOT NULL ,
Cree_Par INT NOT NULL ,
D_Arr BIT NOT NULL ,
Obj_Demarrage DATE NOT NULL ,
Obj_Fin DATE NOT NULL ,
Type_BI CHAR (2) NOT NULL ,
INSPECT INT NOT NULL ,
VERIF INT NOT NULL ,
Machine VARCHAR (13) NOT NULL ,
Priorite INT NOT NULL ,
Date_Fin_Trav DATETIME NULL ,
Commentaire VARCHAR(80) NULL
)
GO

当我尝试将Date_Fin_Trav的值设置为TDateTimePicker时,我在此行中出现了错误:

DateTimePicker1.DateTime := FDTable1Date_Fin_Trav.Value;

错误:

  

[Dcc32错误] Unit1.pas(53):E2010不兼容的类型:' TDateTime'和' TSQLTimeStamp'

所以我将代码更改为:

DateTimePicker1.DateTime := TimeStampToDateTime( FDTable1Date_Fin_Trav.Value);

Type

而导致错误
  

[Dcc32错误] Unit1.pas(53):E2010不兼容的类型:' TTimeStamp'和' TSQLTimeStamp'

所以我的问题是:如何将TSQLTimeStamp转换为TDateTime

2 个答案:

答案 0 :(得分:3)

使用Data.SqlTimSt单元中的SQLTimeStampToDateTime()功能:

  

将TSQLTimeStamp值转换为TDateTime值。

答案 1 :(得分:0)

使用SQLTimeStampToDateTime()功能或EncodeDateEncodeTime

DateTimePicker1.DateTime := EncodeDate(FDTable1Date_Fin_Trav.Value.Year , FDTable1Date_Fin_Trav.Value.Month , FDTable1Date_Fin_Trav.Value.Day)
+ EncodeTime(FDTable1Date_Fin_Trav.Value.Hour , FDTable1Date_Fin_Trav.Value.Minute , FDTable1Date_Fin_Trav.Value.Second ,
FDTable1Date_Fin_Trav.Value.Fractions);