如何以毫秒为单位在SQL Server中打印GETDATE()? [英] How to print GETDATE() in SQL Server with milliseconds in time?

查看:129
本文介绍了如何以毫秒为单位在SQL Server中打印GETDATE()?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要打印 GETDATE()在SQL Server 2008中,我需要以毫秒为单位的时间(这是出于调试目的-查找sp的执行时间)

I want to print GETDATE() in SQL Server 2008, I need the time with milliseconds (this is for debugging purpose - to find sp's execution time )

我发现这种差异


  • SELECT GETDATE()返回 2011-03 -15 18:43:44.100

  • print GETDATE()返回 2011年3月15日6:44 PM

  • SELECT GETDATE() returns 2011-03-15 18:43:44.100
  • print GETDATE() returns Mar 15 2011 6:44PM

我认为SQL Server自动在打印功能中进行类型转换。

I think SQL Server automatically typecast in print functionality.

我需要打印这样的日期 2011-03-15 18:43:44.100

I need to print the date like this 2011-03-15 18:43:44.100

感谢您的帮助。

推荐答案

首先,如果可能,您应该使用 SYSDATETIME()

First, you should probably use SYSDATETIME() if you're looking for more precision.

要以毫秒为单位设置数据格式,请尝试 CONVERT(varchar,SYSDATETIME(),121)

To format your data with milliseconds, try CONVERT(varchar, SYSDATETIME(), 121).

有关其他格式,请在 CAST <上查看 MSDN页面/ code>和转换

For other formats, check out the MSDN page on CAST and CONVERT.

这篇关于如何以毫秒为单位在SQL Server中打印GETDATE()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆