DateTime fields from SQL Server display incorrectly in Excel

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

    I've had this same problem for a while as I generate a fair number of ad-hoc reports from SQL Server and copy/paste them into Excel. I would also welcome a proper solution but my temporary workaround was to create a default macro in Excel which converts highlighted cells to Excel's datetime format, and assigned it to a hotkey (Shift-Ctrl-D in my case). So I open Excel, copy/paste from SSMS into a new Excel worksheet, highlight the column to convert and press Shift-Ctrl-D. Job done.

    0 讨论(0)
  • 2020-12-12 16:59

    Found a solution that doesnt requires to remember and retype the custom datetime format yyyy-mm-dd hh:mm:ss.000

    • On a new cell, write either =NOW() or any valid date+time like 5/30/2017 17:35: It will display correctly in your language, e.g. 5/30/2017 5:35:00 PM
    • Select the cell, click on the Format Painter icon (the paint brush)
    • Now click on the row header of the column that you want to apply the format.

    This will copy a proper datetime format to the whole column, making it display correctly.

    0 讨论(0)
  • 2020-12-12 17:02

    I know it is too late to answer to this question. But, I thought it would still be nice to share how I sorted this out when I had the same issue. Here is what I did.

    • Before copying the data, select the column in Excel and select 'Format cells' and choose 'Text' and click 'Ok' (So, if your SQL data has the 3rd column as DateTime, then apply this formatting to the 3rd column in excel)
    • Now, copy and paste the data from SQL to Excel and it would have the datetime value in the correct format.
    0 讨论(0)
提交回复
热议问题