DateTime fields from SQL Server display incorrectly in Excel

后端 未结 9 610
独厮守ぢ
独厮守ぢ 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:46

    I had the same problem as Andre. There does not seem to be a direct solution, but a CAST in the query that generates the data fixes the problem as long as you can live within the restrictions of SMALLDATETIME. In the following query, the first column does not format correctly in Excel, the second does.

    SELECT GETDATE(), CAST(GETDATE() AS SMALLDATETIME)

    Perhaps the fractional part of the seconds in DATETIME and DATETIME2 confuses Excel.

提交回复
热议问题