Posts Tagged ‘DATEDIFF’

SQL Server: DATEDIFF limitations

This item was filled under [ SQL Server ]

DATEDIFF produces an error if the result is out of range for integer values. For milliseconds, the maximum number is 24 days, 20 hours, 31 minutes and 23.647 seconds. For seconds, the maximum number is 68 years.
Source: Transact-SQL Reference

Continue reading...

Tagged with: [ , ]

Calculate time difference in hh:mm

This item was filled under [ SQL Server ]

A simple query that computes time difference between two dates and displays the result in “hh:mm” format.

– 2008-08-10 00:00:04 < Start_Time
– 2008-08-10 08:32:17 < End_Time
– 8:32 << Output (HHMM_Duration)

SELECT Start_Time, End_Time,
CONVERT(VARCHAR, DATEDIFF(hour, Start_Time, End_Time)) + ':' + CONVERT(VARCHAR, DATEDIFF(minute, Start_Time, End_Time)%60) as HHMM_Duration
FROM Events

*The above query was executed on Microsoft SQL Server 2000.

Continue reading...