var Rq: TDateTime; .... with TQuery.Create(OWner) do begin DatabaseName := 'Demo'; Sql.Text := 'select getdate() Rq from Your_table'; Active := True; rq := FieldByName ('Rq').AsDateTime; end;取得当前的时间: table.FieldByName('字段名').asDateTime:=Time; 取得当前的日期: table.FieldByName('字段名').asDateTime:=Date; 同时取得日期和时间则和liwei示意的一样. Query1.Fieldbyname('相应的字段').ASDATETIME:=NOW;需要注意的是如果你不用asDatetime:=Time or Date or Now 而是用asString:=则需要用DateTimeToStr(Now), DateToStr(Now),TimeToStr(Time).
可以用copy命令实现 首先取出数据库中的时间记录: s := findbyfield('fieldname').asstring; 用copy:copy (s,11,length(s));
这是我的思路,可以参考一下:var currTime,dbTime :TDateTime; begin dbTime:= ADOQuery1.FieldByName('thetime').AsDateTime; currTime := date; if FormatDateTime('hh:mm:ss',dbTime)=FormatDateTime('hh:mm:ss',currTime) then showmessage('时间相同,不过这似乎不太可能!') else if FormatDateTime('hh:mm:ss',dbTime)<FormatDateTime('hh:mm:ss',currTime) then showmessage('数据表中的时间比当前时间要小!'); end;
Rq: TDateTime;
....
with TQuery.Create(OWner) do
begin
DatabaseName := 'Demo';
Sql.Text := 'select getdate() Rq from Your_table';
Active := True;
rq := FieldByName ('Rq').AsDateTime;
end;取得当前的时间:
table.FieldByName('字段名').asDateTime:=Time;
取得当前的日期:
table.FieldByName('字段名').asDateTime:=Date;
同时取得日期和时间则和liwei示意的一样.
Query1.Fieldbyname('相应的字段').ASDATETIME:=NOW;需要注意的是如果你不用asDatetime:=Time or Date or Now
而是用asString:=则需要用DateTimeToStr(Now),
DateToStr(Now),TimeToStr(Time).
首先取出数据库中的时间记录:
s := findbyfield('fieldname').asstring;
用copy:copy (s,11,length(s));
currTime,dbTime :TDateTime;
begin
dbTime:= ADOQuery1.FieldByName('thetime').AsDateTime;
currTime := date;
if FormatDateTime('hh:mm:ss',dbTime)=FormatDateTime('hh:mm:ss',currTime) then
showmessage('时间相同,不过这似乎不太可能!')
else if FormatDateTime('hh:mm:ss',dbTime)<FormatDateTime('hh:mm:ss',currTime) then
showmessage('数据表中的时间比当前时间要小!');
end;