Menu & Search

Copying Dates into Excel

Copying Dates into Excel

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

I don’t think Excel likes the milliseconds.

Copy Data to Excel Format

This is the data I tried to copy over.

Copy SQL Data Highlight

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
Copy SQL Smalldatetime to Excel

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!