2010-03-31 96 views
1

我們如何在vb中提取系統時間並進行計算。然後添加或減去時間,然後將更改時間以較早的格式存儲在oracle數據庫表中。vb中日期的操縱

回答

4

爲了得到系統時間

Dim timestamp As Date: timestamp = Now 
timestamp = timestamp - Int(timestamp) 

加上或減去一個時間間隔(如加一小時)

timestamp = DateAdd("h", 1, timestamp) 

若要將其存儲在數據庫中,像

Dim cnn As New Connection 
cnn.ConnectionString = "YourConnectionString" 

Dim cmd As New Command 
cmd.CommandType = adCmdStoredProc 
cmd.CommandText = "YourStoredProcName" 
cmd.ActiveConnection = cnn 

Dim prm As Parameter: Set prm = cmd.CreateParameter("YourParameterName", adDBTime, adParamInput) 
prm.Value = timestamp 

Call cmd.Parameters.Append(prm) 
Call cnn.Open 
Call cmd.Execute 
Call cnn.Close 
+0

@AdamRalph:如何減少時間? DateSub()不工作... – banita 2010-03-31 17:09:30

+0

通過採取負值的工作表示感謝。 – banita 2010-03-31 17:11:48