How to minus between two time in a column ?

Analyst_SQL 3,576 Reputation points
2023-11-07T13:17:40.1966667+00:00

I want difference between two time ,

Create table #conIssuance (ID int,CID varchar(50),E_Date date,E_Time Time(7),QTY int)

Insert into #conIssuance values (11101,'Saver' ,'2023-11-07','08:00',1)
Insert into #conIssuance values (11102,'Saver' ,'2023-11-07','08:10',1)
Insert into #conIssuance values (11103,'Saver' ,'2023-11-07','08:18',1)
Insert into #conIssuance values (11104,'Saver' ,'2023-11-07','08:25',1)
Insert into #conIssuance values (11105,'Army' ,'2023-11-07','08:35',1)



Output

Last row will be subtract from 8:50

User's image

SQL Server Reporting Services
SQL Server Reporting Services
A SQL Server technology that supports the creation, management, and delivery of both traditional, paper-oriented reports and interactive, web-based reports.
3,063 questions
SQL Server Integration Services
SQL Server Integration Services
A Microsoft platform for building enterprise-level data integration and data transformations solutions.
2,703 questions
Developer technologies | Transact-SQL
SQL Server | Other
0 comments No comments
{count} votes

Accepted answer
  1. Viorel 122.6K Reputation points
    2023-11-07T15:58:19.98+00:00

    Check this query:

    select ID, CID, E_Date, datediff(minute, E_Time, coalesce(lead(E_Time) over (order by E_Date, E_Time), '08:50')) as Minutes
    from #conIssuance 
    order by E_Date, E_Time
    

    (Assuming that the time does not pass the midnight).

    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.