Calculating timespan with t-sql

前端 未结 7 1778
时光取名叫无心
时光取名叫无心 2020-11-30 07:32

Given two date/times:

@start_date = \'2009-04-15 10:24:00.000\'
@end_date = \'2009-04-16 19:43:01.000\'

Is it possible to calculate the tim

7条回答
  •  时光取名叫无心
    2020-11-30 07:59

    DATEDIFF can return unintuitive values. For example, the two dates below differ by one second yet DATEDIFF with the parameters below and interpreted as others have interpreted it above returns 1 year:

    SELECT DATEDIFF(year, '2005-12-31 23:59:59', '2006-01-01 00:00:00')

    Look at the MSDN documentation for DATEDIFF to understand how it works.

提交回复
热议问题