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
 SQL Server 2008 Forums
 Transact-SQL (2008)
 DateTime Issue

Author  Topic 

sidharth.banyal
Starting Member

11 Posts

Posted - 2009-08-28 : 10:34:56
I have a problem with DateTime.
I want to calculate hours occupied for a timespan which i will give as a input.
In my table i have two columns
DateFrom
DateTo
these columns contain information that from this date to this date i have a booking.
Now i want to calculate hours for a particular timespan means that in that timespan how many hours are occupied.
Basically result should contain sum of all hours which i have in that range.

Can anyone help?


Sidharth Banyal

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-08-28 : 11:03:55

select sum(datediff(hour,datefrom,dateto)) from your_table
where ..........

Madhivanan

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

sidharth.banyal
Starting Member

11 Posts

Posted - 2009-08-28 : 11:25:02
thanks a lot

Sidharth Banyal
Go to Top of Page
   

- Advertisement -