問題描述
我如何將時間格式 " 10:02:22 PM " 轉換為 SQL Server 日期時間格式.
How do i convert the Time format " 10:02:22 PM " into an SQL Server DateTime Format.
我有一列這樣的數據.我從 CSV 文件導入了此列,現在想將其轉換為日期時間格式,以便我能夠使用日期時間函數.
I have a column of such data. I imported this column from a CSV File and now want to convert it into a DateTime Format so that i can be able to use Date Time Functions.
我希望能夠將此列插入到另一個具有正確日期時間格式的表中.
I want to be able to insert this column into another table with correct DateTime format.
推薦答案
使用此鏈接:http://msdn.microsoft.com/en-us/library/ms187928.aspx.
僅用于時間轉換...
SELECT CONVERT( TIME, '10:00:22 PM' );
給出以下輸出...
22:00:22.000000
帶有日期和時間的時間轉換...
Time conversion with date and time...
SELECT CONVERT( DATETIME, '10:00:22 PM' );
給出以下輸出...
1900-01-01 22:00:22.0000
注意:對于datetime
,您需要將特定日期作為輸入,否則會考慮默認世紀日期.
Note : For datetime
you need to have specific date as input otherwise it consider default century date.
這篇關于在 SQL Server 中將 Varchar 轉換為時間的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!