0
在我的.net winform應用程序中,我將excel數據導入到SQL服務器。在我的Excel表中,我有'STRT_TM'列,其中包含03/01/2017 21:33:22格式的日期。我想做顯式轉換,因爲在隱式轉換中,convert函數無法確定日期是dd/mm/yyyy還是mm/dd/yyyy。將字符串列轉換爲DataTime
在Sql Server中,我試圖將字符串轉換爲日期。這裏是代碼
select convert(smalldateTime,SUBSTRING('03/01/2017 14:05:34',7,4)+
SUBSTRING('03/01/2017 14:05:34',1,2) + SUBSTRING('03/01/2017 14:05:34',4,2))
結果是2017年3月1日00:00:00 但是當我嘗試包括一部分時間提示錯誤。 這裏是代碼。
select convert(smalldateTime,SUBSTRING('03/01/2017 14:05:34',7,4)+
SUBSTRING('03/01/2017 14:05:34',1,2) + SUBSTRING('03/01/2017 14:05:34',4,2) +
Substring('03/01/2017 14:05:34',12,8))
和錯誤是
Msg 295, Level 16, State 3, Line 3
Conversion failed when converting character string to smalldatetime data type.
任何幫助將不勝感激。