Click here to Skip to main content
15,908,264 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How to calculate business hours between days in sql server 2008?
Please help let me know very urgently.
Posted
Updated 6-Jan-14 3:00am
v2
Comments
Karthik_Mahalingam 6-Jan-14 8:51am    
what do you mean by business hours,

can you pls post your code...
Kornfeld Eliyahu Peter 6-Jan-14 9:00am    
Try to be nice and polite when you ask for something - it helps!
Karthik_Mahalingam 6-Jan-14 22:07pm    
agreed kornfeld :)
JasonMacD 6-Jan-14 9:24am    
We need more information specific to what you are trying to accomplish. Don't be so vague, and you'll usually get a answer pretty quick, otherwise you'll never get an answer.

1 solution

SQL
SET DATEFIRST 7

declare @start as date
declare @end as date

set @start = '17/12/2013'
set @end = '17/01/2014'

declare @start_hr as time
declare @end_hr as time

set @start_hr = '9:00'
set @end_hr = '17:00'

declare @workdayscount as int

set @workdayscount = 0

while @start < @end
begin
	set @workdayscount = @workdayscount + case when datepart(weekday, @start) in (1, 2, 3, 4, 5) then 1 else 0 end
		
	set @start = dateadd(day, 1, @start)
end

select @workdayscount
select @workdayscount * datediff(hour, @start_hr, @end_hr)

1. SET DATEFIRST 7 - sets the first weekday to Saunday.
2. The list (1, 2, 3, 4, 5) represents the working days - form Sunday to Thursday
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900