How to print GETDATE() in SQL Server with milliseconds in time?
First, you should probably use SYSDATETIME()
if you're looking for more precision.
To format your data with milliseconds, try CONVERT(varchar, SYSDATETIME(), 121)
.
For other formats, check out the MSDN page on CAST
and CONVERT
.
SELECT CONVERT( VARCHAR(24), GETDATE(), 113)
UPDATE
PRINT (CONVERT( VARCHAR(24), GETDATE(), 121))
If your SQL Server version supports the function FORMAT you could do it like this:
select format(getdate(), 'yyyy-MM-dd HH:mm:ss.fff')