教您如何實(shí)現(xiàn)同步SQL Server日期時(shí)間
作者:佚名
下文為您介紹的是如何實(shí)現(xiàn)同步SQL Server日期時(shí)間的方法,供您參考學(xué)習(xí),如果您在這方面遇到過(guò)類似的問(wèn)題,不妨一看。
SQL Server日期是很重要的,在我們使用SQL Server數(shù)據(jù)庫(kù)的過(guò)程中,有時(shí)候會(huì)需要SQL Server服務(wù)器時(shí)間和本地系統(tǒng)時(shí)間保持同步,下面就為您介紹這種實(shí)現(xiàn)同步SQL Server日期時(shí)間的方法。
- //同步SQL_Server服務(wù)器時(shí)間日期的過(guò)程
- procedure TDM.SynchronizationSQLServerDateTime();
- var
- TheServerDateTime:TDateTime;//定義服務(wù)器時(shí)間
- TheLocalDateTime:_SystemTime;//定義本地系統(tǒng)時(shí)間 引用 windows
- Year,Month,Day:Word;//定義年月日
- Hour,Min,Sec,MSec:Word;//定義時(shí)分秒毫秒
- begin
- with CommonQuery do begin
- SQL.Clear;
- SQL.Add('select GetDate() as 服務(wù)器時(shí)間');
- Open;
- TheServerDateTime := FieldByName('服務(wù)器時(shí)間').AsDateTime;
- end;
- DecodeDate(TheServerDateTime,Year,Month,Day);//分解服務(wù)器年月日
- DecodeTime(TheServerDateTime,Hour,Min,Sec,MSec);//分解服務(wù)器時(shí)間
- //-------設(shè)定本地系統(tǒng)時(shí)間
- TheLocalDateTime.wYear:=Year;
- TheLocalDateTime.wMonth:=Month;
- TheLocalDateTime.wDay:=Day;
- TheLocalDateTime.wHour:=Hour;
- TheLocalDateTime.wMinute:=Min;
- TheLocalDateTime.wMilliseconds:=MSec;
- SetlocalTime(TheLocalDateTime);//更改本地系統(tǒng)時(shí)間
- end;
以上就是實(shí)現(xiàn)同步SQL Server日期時(shí)間的方法。
【編輯推薦】
帶您學(xué)習(xí)SQL存儲(chǔ)過(guò)程
責(zé)任編輯:段燃
來(lái)源:
互聯(lián)網(wǎng)