How to Properly Copy SQL Dates into Excel

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.

Copy SQL Data Highlight

>>

Copy SQL Date tp Excel

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.

Copy Data to Excel Format

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:

Copy SQL Data to Excel Smalldatetime

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

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 does the trick for me.


Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

Recent Posts
Categories
Tags

Always On Availability Groups (AAG) (4) AWS (4) AWS Redshift (6) Database Admin (72) Database Backups & Recovery (14) Database Mirroring (2) Error Messages (5) Failover Cluster Instances (FCI) (1) Git Commands (6) Importing & Exporting Data (2) Linked Servers (3) Linux Administration (2) Logging & Monitoring (1) Microsoft Patching (2) MySQL (4) Postgres (6) PowerShell Scripts (2) SQL Certificates & Encryption (3) SQL Server Agent (5) SQL Server CDC (2) SQL Server Data Types (2) SQL Server Management Studio (SSMS) (17) SQL Server Networking (3) SQL Server on Linux (1) SQL Server Patching (2) SQL Server Performance Tuning (6) SQL Server Processes (SPIDs) (7) SQL Server Replication (2) SQL Server Scripts (13) SQL Server Security (4) SQL Server Storage (10) Windows Admin (20) Windows Authentication (2) Windows Automation (1) Windows Events (2) Windows Firewall (4) Windows Subsystem for Linux (WSL) (18)