DateTime fields from SQL Server display incorrectly in Excel

后端 未结 9 616
独厮守ぢ
独厮守ぢ 2020-12-12 16:34

Countless times during the day I am copying and pasting records from SQL Server Management Studio to Excel.

My problem is that a DateTime value such as

9条回答
  •  北荒
    北荒 (楼主)
    2020-12-12 16:37

    Although not a complete answer to your question, there are shortcut keys in Excel to change the formatting of the selected cell(s) to either Date or Time (unfortunately, I haven't found one for Date+Time).

    So, if you're just looking for dates, you can perform the following:

    1. Copy range from SQL Server Management Studio
    2. Paste into Excel
    3. Select the range of cells that you need formatted as Dates
    4. Press Ctrl+Shift+3

    For formatting as Times, use Ctrl+Shift+2.

    You can use this in SQL SERVER

    SELECT CONVERT(nvarchar(19),ColumnName,121) AS [Changed On] FROM Table

提交回复
热议问题