2011-11-14 94 views
1

如何在Visual Basic中設置日期格式爲sql 121樣式(即yyyy-mm-dd hh:mi:ss.mmm)。VB和SQL日期時間

我意識到這種格式不在對象的FormatDateTime列表中。

我想將這種格式用於Reporting Services。

回答

0

因爲這幫助了我,我以爲我想補充一點。 如果作爲字符串傳入方法,則:

Shared SomeFunction(ByRef sStartDate as String) 
Dim StartTime As DateTime = DateTime.Parse(sStartDate) 
command.Connection = connection 
command.CommandType = CommandType.StoredProcedure 
command.CommandText = "SomeStoredProcedure" 
command.Parameters.Add("@StartDateTime", SqlDbType.DateTime) 
command.Parameters("@StartDateTime").Value = StartTime.ToString("yyyy-MM-dd HH:mm:ss.fff") 

乾杯!