Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Subracting Time in SQL 2008

Author  Topic 

yanaho
Starting Member

20 Posts

Posted - 2010-07-02 : 10:00:48
Hello, I'm trying to subract time values.
Here is the scenario.
I have a time Column, and a duration column, both datatype is Time(0)

I need to subtract the duration value from the time value, to give me a starttime result.

For example
Time = '11:00:00'
Duration = '00:05:00'
StartTime = '10:55:00'

Any help would be appreciated.

Thanks in advance.

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-07-02 : 10:36:52
select cast(cast(Time as datetime)-CAST(Duration as datetime) as time) as starttime from table


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

yanaho
Starting Member

20 Posts

Posted - 2010-07-02 : 10:44:38

quote:
Originally posted by madhivanan

select cast(cast(Time as datetime)-CAST(Duration as datetime) as time) as starttime from table



Awesome! Thanks. I would have that though with the implementation of time datatypes, that this could be done without casting.

Regardless, much appreciated.
Go to Top of Page
   

- Advertisement -