Using DATEDIFF_BIG

The DATEDIFF function returns a number of time units crossed between two specified dates. The function accepts the following three input arguments:

  • datepart: This is the time unit (year, quarter, monthsecond, millisecond, microsecond, and nanosecond)
  • startdate: This is an expression of any date data type (date, time, smalldatetime, datetime, datetime2, and datetimeoffset)
  • enddate: This is also an expression of any date data type (date, time, smalldatetime, datetime, datetime2, and datetimeoffset)

The return type of the function is int. This means that the maximum returned value is 2,147,483,647. Therefore, if you specify minor units (milliseconds, microseconds, or nanoseconds) as the first parameters of the function, ...

Get SQL Server 2017 Developer's Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.