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)
 Calculating Time Difference (working days)

Author  Topic 

peitech
Starting Member

10 Posts

Posted - 2012-03-06 : 08:30:09
Guys,

I'm trying to calculate the time difference between two datetime strings, however, if any non work days (definied as Saturday and Sunday where we are) are within the range they should be ignored.

The best I've come up with is using the difference in week number between the two datetime fields and multiplying this by 48. I then subtract the result of this from the standard datediff function returning hours.

I've been told a calendar table is the way to go to get this to take account of holidays etc, however, I don't understand how I could use this to return time differences, I can see how you'd use it to say how many 'work days' between date x and y, but not how many hours where the days are workdays.

Can anyone give me any tips here?

X002548
Not Just a Number

15586 Posts

Posted - 2012-03-06 : 10:03:45
you create a calendar table...with a column that says what type of day it is

Then you join you table to the calendar table where type not in



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx


Want to help yourself?

http://msdn.microsoft.com/en-us/library/ms130214.aspx

http://weblogs.sqlteam.com/brettk/

http://brettkaiser.blogspot.com/


Go to Top of Page
   

- Advertisement -