How to Properly Copy SQL Dates into Excel

sqldba.blogMore of my SQL Server writing is at sqldba.blog, including the current take on SQL Server scripts: the DBA Scripts hub.

Copy a DATETIME column from the SSMS results grid into Excel and the dates turn into 00:00.0. The dates are not lost. Excel has read them as dates, then picked a minutes-and-seconds display format because of the milliseconds. Fix it in Excel with a custom cell format, or in the query by converting the dates to text before you copy them.


Why Excel Shows 00:00.0 Instead of the Date

Here’s an example of data I copied over from SQL Server into an Excel sheet.

SSMS results grid with the OrderDate column selected, five DATETIME values with milliseconds
The dates pasted into Excel show as 23:45.1 and similar, with the Format Cells dialog open on Custom

A DATETIME copied from SSMS carries milliseconds, like 2010-12-29 00:00:00.000. Excel recognises that as a date and time, but gives the cell the custom format mm:ss.0, which shows only minutes, seconds and tenths of a second. These order dates are all at midnight, so every cell shows zeros. The full date and time is still the cell’s value; only the display is wrong.


Fix It in Excel: Set a Custom Format

  1. Select the date columns.
  2. Press Ctrl+1 to open Format Cells.
  3. On the Number tab, choose Custom.
  4. In Type, enter yyyy-mm-dd hh:mm:ss.000 and click OK.
Excel Format Cells, Custom, with yyyy-mm-dd hh:mm:ss.000 in Type and the sample showing 2026-11-27 10:23:45.127

With that format a pasted 2026-11-27 10:23:45.127 displays exactly as SQL Server returned it, milliseconds included. Use dd/mm/yyyy hh:mm:ss instead if you would rather see the date the way your regional settings write it.

Here it is after clicking OK. I had only cell A1 selected, so A1 shows the full date and the cells below still show the minutes-and-seconds view. Select the whole column first to format them all.

After OK, cell A1 shows 2026-11-27 10:23:45.127 while the unformatted cells below still show 05:02.5 and similar

Fix It in the Query: CONVERT with Style 120

If you would rather the paste just works, convert the dates to text in the query. Style 120 returns yyyy-mm-dd hh:mi:ss with no milliseconds:

SQL
SELECT
    CustomerPONumber,
    CONVERT(char(19), OrderDate, 120) AS OrderDate,  -- 2010-12-29 00:00:00
    CONVERT(char(19), DueDate, 120) AS DueDate,
    CONVERT(char(19), ShipDate, 120) AS ShipDate
FROM dbo.FactResellerSales
WHERE CustomerPONumber = 'PO522145787';
  • Style 120 cuts the milliseconds off; it does not round. Excel reads the text as a proper date and applies its default date and time format from your regional settings (dd/mm/yyyy hh:mm on a UK machine). That format hides the seconds, but they are still in the value; the custom format above shows them.
  • Style 121 (CONVERT(char(23), OrderDate, 121)) keeps the milliseconds, which brings back 00:00.0, so pair it with the custom format.

Why Not SMALLDATETIME?

Casting to SMALLDATETIME also drops the milliseconds and pastes cleanly:

Copy SQL Data to Excel Smalldatetime
Copy SQL Smalldatetime to Excel

The catch is that SMALLDATETIME rounds to the nearest minute, so 10:23:45 becomes 10:24:00. That is harmless for dates at midnight like these, and wrong for anything where the seconds matter. Style 120 keeps them.

On SSMS 22.4.1 or later you can skip the clipboard altogether and save the results grid straight to an Excel file, covered in SSMS Results Grid: Export to Excel, JSON and Markdown on sqldba.blog.

Comments

Leave a Reply

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