如何在两次之间找到以毫秒为单位的时间跨度?

时间:2012-04-10 15:57:59

标签: sql sql-server tsql datetime timespan

使用TSQL如何找到两次之间的差异,以毫秒为单位?

declare @start datetime = '2012-04-10 14:59:12.863',
    @end datetime = '2012-04-10 14:59:13.800'

select  @start, @end, 'TODO: get timespan in milliseconds between @start and @end'

1 个答案:

答案 0 :(得分:6)

将datediff函数用作documented here.

declare @start datetime = '2012-04-10 14:59:12.863',     
    @end datetime = '2012-04-10 14:59:13.800'     

select datediff(ms, @start, @end) 

ms是datepart缩写,以毫秒为单位。