Thursday, September 3, 2009

To Find the Difference between two time intervals use the following code in SQL Server

Use the following code to find the difference between two time intervals.

abs(datediff(hh, DTD_TimeOut , DTD_TimeIn)) as Hours
,abs(datediff(mi, DTD_TimeOut , DTD_TimeIn)%60) as Minutes

Where DTD_TimeOut,DTD_TimeIn are the timein and timeout fields in the database. Hours and Minutes are the alias names to output the Hours and Minutes.(abs is used to return the absolute value because sometimes it will return 3.00)

0 comments:

.