There’s often a need to quickly copy/paste a database query output into an Excel sheet, rather than exporting as a .csv file. When you do this for a DATETIME column though, it’ll show up in Excel looking something like this.
![Copy SQL Date tp Excel](https://peter-whyte.com/wp-content/uploads/2018/07/copying_data_to_excel_paste.png)
I don’t think Excel likes the milliseconds.
![Copy Data to Excel Format](https://peter-whyte.com/wp-content/uploads/2018/07/copying_data_to_excel_cell_format.png)
This is the data I tried to copy over.
![Copy SQL Data Highlight](https://peter-whyte.com/wp-content/uploads/2018/07/copying_data_to_excel_selection.png)
To resolve, just convert the DATETIME columns to SMALLDATETIME, then go ahead with the copy/paste to Excel using the default Cell Format.
![Copy SQL Data to Excel Smalldatetime](https://peter-whyte.com/wp-content/uploads/2018/07/copying_data_to_excel_selection_smalldatetime.png)
![Copy SQL Smalldatetime to Excel](https://peter-whyte.com/wp-content/uploads/2018/07/copying_data_to_excel_paste_smalldatetime.png)
I’d be interested to know if there’s an easier way to sort this on the Excel side. For now, the above will do the trick for me!
Leave a Reply