2013-07-24 81 views
0

如何從時間字段中刪除秒數? 我想:SSRS - 從時間字段中刪除秒數

=Rset(Fields!hr_saida.Value,5) = return #Error 
=TimeValue(Fields!hr_saida.Value) = return #Error 
=FormatDateTime(CDate(Fields!hr_saida.Value),"hh:mm") = return #Error 

我也試圖把我的文本框屬性號碼> 13:30,但仍顯示「HH:MM:SS」 如何刪除?謝謝。

回答

4

除了從@Yuriy所述一個另一種選擇是:

=Format(Fields!hr_saida.Value, "HH:mm") 

爲24小時時間

或:

=Format(Fields!hr_saida.Value, "hh:mm") 

用於AM/PM。

如果您的字段不是日期時間,您可能還需要使用CDate()。評論後

編輯

嘗試:

=Left(Fields!hr_saida.Value.ToString(), 5) 

RSet還與ToString

這24小時的時間工作 - 你可以使用類似:

=CDate(Fields!hr_saida.Value.ToString()).ToString("hh:mm") 

的AM/PM。

在我的測試我是越來越喜歡類似的錯誤:

Unable to cast object of type 'System.TimeSpan' to type 'System.IConvertible'. 

從類型「時間跨度」的轉換輸入「日期」是無效的。

我想這裏的結論是,SSRS 真的不喜歡在SQL Server時間數據類型。

+0

如果該字段實際上包含日期時間值,則使用文本框的格式屬性(設置爲「HH:mm」),以便導出將保留該值。 –

+0

@JamieF,一如既往的有用評論!只是顯示可能是最好的解決方案的價值;實際上使用'Format'在使用該值附加到較大的字符串時最爲有用。 –

+0

我的領域是時間(7),我嘗試過CDate()之前,但仍然得到相同的錯誤 – migmig

1

使用4選項FormatDateTime函數。

=FormatDateTime(Fields!hr_saida.Value, 4) 

應該這樣做。

+0

仍然返回「#Error」 – migmig

+0

什麼類型是「Fields!hr_saida.Value」?如果你簡單的輸出'= Fields!hr_saida.Value,''會發生什麼? –

+0

我得到「hh:mm:ss」,類型爲「time(7)」 – migmig