Hello - I have the below function ( source: http://ask.sqlteam.com/questions/110...urther-queries) that basically calculates the business hours/minutes elapsed between two ** smalldatetime** fields: - set ANSI_NULLS ON
-
set QUOTED_IDENTIFIER ON
-
go
-
-
ALTER FUNCTION [dbo].[getBusinessHours] (@smalldatetime1 smalldatetime, @smalldatetime2 smalldatetime)
-
-
RETURNS bigint
-
-
AS
-
-
BEGIN
-
-
DECLARE @Diff bigint;
-
DECLARE @adjusted_1 smalldatetime;
-
DECLARE @adjusted_2 smalldatetime;
-
-
SET @adjusted_1 = case when @smalldatetime1 - dateadd(day, datediff(day, 0, @smalldatetime1), 0) < '18:00' then @smalldatetime1 else dateadd(day, datediff(day, 0, @smalldatetime1), 0) + case when datename(weekday,@smalldatetime1) in ('saturday','sunday') then '17:30' else '18:00' end end;
-
-
SET @adjusted_2 = case when @smalldatetime2 - dateadd(day, datediff(day, 0, @smalldatetime2), 0) > '08:30' then @smalldatetime2 else dateadd(day, datediff(day, 0, @smalldatetime2), 0) + case when datename(weekday,@smalldatetime1) in ('saturday','sunday') then '09:30' else '08:30' end end;
-
-
SET @Diff = case when datename(weekday,@smalldatetime1) in ('saturday','sunday') then datediff(minute, @adjusted_1, @adjusted_2) - (datediff(day, @adjusted_1, @adjusted_2) * 960) else datediff(minute, @adjusted_1, @adjusted_2) - (datediff(day, @adjusted_1, @adjusted_2) * 870) end;
-
-
return @Diff
-
-
END
The problem I am facing is that the function fails to calculate the business hours correctly if the "**smalldatetime1**" falls between ** 12:00 AM** and ** 8:30 AM**.
Also FYI -
- smalldatetime1 is the date/time when a call is logged into the database.
- smalldatetime2 is the date/time when the call was closed.
Now basically I would like to track the calls that took more than 24 hrs / 4 hrs to close, only considering business hours, which is:
- 8:30 AM - 6:00 PM on Weekdays
- 9:30 AM - 5:30 PM on Weekends
Any help would be much appreciated.
Thanks!
How about this
In your function the first thing you should do is check @smalldatetime1 to see if it is less than the start time for that day.
If it is then adjust @smalldatetime1 so that it is equal to the start time for that day.
Now do your calciulation using the adjusted
@smalldatetime1
2 4461
How about this
In your function the first thing you should do is check @smalldatetime1 to see if it is less than the start time for that day.
If it is then adjust @smalldatetime1 so that it is equal to the start time for that day.
Now do your calciulation using the adjusted
@smalldatetime1
@Delerna
Hello - thanks for your response.
Much appreciate it.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Monty |
last post by:
Let's say you provide an online service from 7:00AM to 6:00PM Eastern
Time (daylight time in the summer). Is there way of showing these
hours of availability on a web page in the user's local...
|
by: Mel |
last post by:
Hi,
I have a text I called txtdate which is the system date or date today.How
can I set the txtdate.text=8/29/04 even if the date today is equal to
8/30/04.Our business hours starts from 8am...
|
by: mitchchristensen |
last post by:
I have a transaction log that tracks issues from a call center. Each
time an issue is assigned to someone else, closed, etc. I get a time
stamp. I have these time stamps for the beginning of an...
|
by: pb648174 |
last post by:
Greeting, below is the complete SQL taken from aspfaq.com (retrieved
from this newsgroup I believe) The query takes about two minutes to
run. Does anybody have a better set based way (sub-second...
|
by: Sam |
last post by:
Hi,
I use C# in my ASP.NET projects. Here's what I need to do: I want to add x
business days to a given date i.e. add 12 business days to today's date. What
is the best, fastest and most...
|
by: iceone |
last post by:
Hi everybody,
I am monitoring a call center and i need to calculate the working hours between the moment the call is answered and the moment the call is closed.
i need to calculate the working...
|
by: bsmeena7005 |
last post by:
Hi
help me to calculate the working hours between 10 to 18 hrs between two dates
including the weekends also no braek or lunch time
Example :-
start date #01-08-2009 08:45:23#
end date ...
|
by: LSGKelly |
last post by:
I have some code in my database that calculates time between two date/time fields and also calculates the weekends and holidays. I did not create this code, so I'm at a bit of a loss why it's not...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
| |