Sqlserver
 sql >> Database >  >> RDS >> Sqlserver

Come dividere il tempo e calcolare la differenza di tempo in SQL Server 2005?

Puoi usare questa query:

select EnrollNo, convert(varchar, AttDateFirst, 8) as FirstTime,
                 convert(varchar, AttDateLast, 8) as LastTime,
                 convert(varchar, AttDateLast - AttDateFirst, 8) as [Time Diff]
from YourTable

per restituire i seguenti risultati:

EnrollNo    FirstTime                      LastTime                       Time Diff
----------- ------------------------------ ------------------------------ ------------------------------
111         08:46:00                       08:46:00                       00:00:00
112         08:30:00                       17:30:00                       09:00:00
302         09:00:00                       18:30:00                       09:30:00
303         10:00:00                       18:35:00                       08:35:00