When copying a SQL query result directly into Excel, DATETIME columns often don’t display as expected. Excel doesn’t seem to handle milliseconds well, making the dates appear messy.
The Issue: Excel Precision Struggles
Here’s an example of data I copied over from SQL Server into an Excel sheet.

>>

The DATETIME values don’t format properly, causing readability issues. It’s shows 00:00:0 instead of the dates.
Excel doesn’t recognize the format type and doesn’t know how to display the data.

The Fix: Convert to SMALLDATETIME
To ensure proper formatting, convert the DATETIME columns to SMALLDATETIME before copying the data into Excel. SMALLDATETIME removes milliseconds, making the values more Excel-friendly.
Example SQL query:

Once pasted into Excel, the dates will appear correctly using Excel’s default cell format.

I’d be interested to know if there’s an easier way to sort this on the Excel side. For now, the above does the trick for me.
Leave a Reply