> 如何傳回 InterBase 資料庫所在機器的現在時間?

InterBase 提供下列命令讓你取得目前的日期時間:

  CURRENT_DATE       傳回日期
  CURRENT_TIME       傳回時間
  CURRENT_TIMESTAMP  傳回日期時間

這裡提供兩種方法:

Sol1.利用以下 SQL 命令取得現在時間:

  select distinct CURRENT_TIMESTAMP from "資料表名稱"

  "資料表名稱"請選擇筆數很少的資料表,執行速度會比較快。

Sol2.撰寫預儲程序:

  SET TERM !! ;

  create procedure "GET_CURRENT_TIMESTAMP" returns ("CUR_TIME" TIMESTAMP) as
  begin
    CUR_TIME = CURRENT_TIMESTAMP;
  end !!

  (以上命令請在 ISQL 中執行)

  然後在 Delphi 程式中,可以使用 TIBStoredProc 元件,像這樣:

  procedure TForm1.Button1Click(Sender: TObject);
  var
    DbSvrTime: TDateTime;
  begin
    IBStoredProc1.StoredProcName := 'GET_CURRENT_TIMESTAMP';
    IBStoredProc1.ExecProc;  
    IBTransaction1.Commit;
    DbSvrTime := IBStoredProc1.Params[0].AsDateTime;
    ShowMessage('DB server 時間為 ' + DateTimeToStr(DbSvrTime));
  end;

    Source: geocities.com/huanlin_tsai/faq

               ( geocities.com/huanlin_tsai)