XXX
XXX

Reputation: 301

How to substract Time in SQL Server 2008 R2

I want to select a time range from the database to get that time range.

eg : if say employee has starttime as 12:00 the range will be 11:45 to 12:15 but i need to calculate it I am able to add but not able to subtract.

My code

select DATEDIFF(MINUTE, 15, Starttime) 
from Employees 
where EmployeeID = 18

select DATEADD(MINUTE, 15, Starttime) 
from Employees 
where EmployeeID = 18

select EmployeeID, StartTime, ReturnTime 
from Employees 
where EmployeeID = 18

Result

This is what i get as a result

But what I want is:

Instead of -20868 - 11:57:12:0000000

like what happens when I ADD 12:12:12 = 12:27:12

Upvotes: 0

Views: 76

Answers (1)

Raj
Raj

Reputation: 10843

Is this what you are looking for?

select DATEADD(MINUTE,-15,Starttime) from Employees where EmployeeID = 18

Upvotes: 2

Related Questions