Delphi가 SQLServer 서버를 취득한 날짜와 시간

928 단어
Delphi가 SQLServer 서버 날짜 및 시간을 가져옵니다.
Function GetSysTime:TDateTime;
var
  Qry: TADOQuery;
begin
    //         yyyy-MM-dd HH:mm:ss
    QryCreate(Qry, frmDM.ADOCon);
    with Qry do
    begin
      Close;
      SQL.Clear;
      SQL.Add('select GetDate() as SysTime');
      Open;
      Result := FieldByName('SysTime').AsDateTime;
      Free;
    end;
end;

Function GetSysDate:TDate;
var
  Qry: TADOQuery;
begin
    //         yyyy-MM-dd
    QryCreate(Qry, frmDM.ADOCon);
    with Qry do
    begin
      Close;
      SQL.Clear;
      SQL.Add('select convert(varchar(10),getdate(),120) as SysDate');
      Open;
      Result := FieldByName('SysDate').AsDateTime;
      Free;
    end;
end;

procedure QryCreate(var aQuery: TADOQuery; Connecion: TAdoConnection);
begin
  aQuery := TADOQuery.create(nil);
  aQuery.Connection := Connecion;
end;

좋은 웹페이지 즐겨찾기