SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Want to Calculate Business Working hours


Want to Calculate Business Working hours

Author
Message
venkatesh-MSBI
venkatesh-MSBI
Grasshopper
Grasshopper (16 reputation)Grasshopper (16 reputation)Grasshopper (16 reputation)Grasshopper (16 reputation)Grasshopper (16 reputation)Grasshopper (16 reputation)Grasshopper (16 reputation)Grasshopper (16 reputation)

Group: General Forum Members
Points: 16 Visits: 117
hi Everyone,

I have one query, i want to calculate the business working hours (like from monday to friday 9 to 5 pm and saturday 9 to 2 pm) for the given 2 dates. And also i want to eliminate the public holidays with in the given dates.



If any one was faced the same situation plz help me.




Regards

Venki
SwePeso
SwePeso
SSCarpal Tunnel
SSCarpal Tunnel (4.2K reputation)SSCarpal Tunnel (4.2K reputation)SSCarpal Tunnel (4.2K reputation)SSCarpal Tunnel (4.2K reputation)SSCarpal Tunnel (4.2K reputation)SSCarpal Tunnel (4.2K reputation)SSCarpal Tunnel (4.2K reputation)SSCarpal Tunnel (4.2K reputation)

Group: General Forum Members
Points: 4177 Visits: 3433
I think there already are about 15 zillion postings about this exact problem.
Try to search this forum for similar requests and see what you get?


N 56°04'39.16"
E 12°55'05.25"
venkatesh-MSBI
venkatesh-MSBI
Grasshopper
Grasshopper (16 reputation)Grasshopper (16 reputation)Grasshopper (16 reputation)Grasshopper (16 reputation)Grasshopper (16 reputation)Grasshopper (16 reputation)Grasshopper (16 reputation)Grasshopper (16 reputation)

Group: General Forum Members
Points: 16 Visits: 117
i got one example, but it is useful only for calculating the number of working days.

url is: http://weblogs.sqlteam.com/brettk/archive/2005/05/12/5139.aspx

If anyone knows my query plz respond me.


Its very urgent.
Kenneth Wilhelmsson
Kenneth Wilhelmsson
SSCrazy
SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)

Group: General Forum Members
Points: 2605 Visits: 699
You may find your way to your answers here:
http://sqlserver2000.databases.aspfaq.com/why-should-i-consider-using-an-auxiliary-calendar-table.html

/Kenneth



Matt Miller (4)
Matt Miller (4)
SSChampion
SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)

Group: General Forum Members
Points: 12659 Visits: 18584
well - let's get some specifics before we go diving into weeks and weeks of back and forth (well - probably will happen anyway.....BigGrin)

Jeff Moden took a running start at whole days in a recent article. [url=http://www.sqlservercentral.com/articles/Advanced+Querying/calculatingworkdays/1660/][/url]

- What do you plan on passing in? Are we dealing with specific work time starts and stops (e.g. 9/1/07 10:20am to 10/15/07 1:55pm) or full days? Are they passed in combined, or separated? (e.g. Start datetime, end datetime vs start date, start time, end date, end time)
- what - no lunch breaks?
- where are you storing your holidays?

----------------------------------------------------------------------------------
Your lack of planning does not constitute an emergency on my part...unless you're my manager...or a director and above...or a really loud-spoken end-user..All right - what was my emergency again?
venkatesh-MSBI
venkatesh-MSBI
Grasshopper
Grasshopper (16 reputation)Grasshopper (16 reputation)Grasshopper (16 reputation)Grasshopper (16 reputation)Grasshopper (16 reputation)Grasshopper (16 reputation)Grasshopper (16 reputation)Grasshopper (16 reputation)

Group: General Forum Members
Points: 16 Visits: 117
We are storing holidays list in seperate table. And also storing the Business hours in that table.

We are storing the data in datetime format. I want to calculate the hours and minutes in between the passed dates(datetime format).


Give me solution Plz


Thanks & Regards
Venki
Kenneth Wilhelmsson
Kenneth Wilhelmsson
SSCrazy
SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)SSCrazy (2.6K reputation)

Group: General Forum Members
Points: 2605 Visits: 699
Ok, could you then please give an example on what this table of yours look like?
A few rows of sample data and the expected output you need from that data.

/Kenneth



venkatesh-MSBI
venkatesh-MSBI
Grasshopper
Grasshopper (16 reputation)Grasshopper (16 reputation)Grasshopper (16 reputation)Grasshopper (16 reputation)Grasshopper (16 reputation)Grasshopper (16 reputation)Grasshopper (16 reputation)Grasshopper (16 reputation)

Group: General Forum Members
Points: 16 Visits: 117
For this i am using 2 tables i.e., Holidays and WorkingHours. We are storing only holidays dates in holidays table. in working hours table 3 columns were there i.e., weekday, starting time, closing time.
we are storing the values like from monday to friday 9 am to 5 pm and for saturday 9 am to 1 pm.

thanks & regards

Venki
Mohammad Mazharuddin Ehsan
Mohammad Mazharuddin Ehsan
Mr or Mrs. 500
Mr or Mrs. 500 (563 reputation)Mr or Mrs. 500 (563 reputation)Mr or Mrs. 500 (563 reputation)Mr or Mrs. 500 (563 reputation)Mr or Mrs. 500 (563 reputation)Mr or Mrs. 500 (563 reputation)Mr or Mrs. 500 (563 reputation)Mr or Mrs. 500 (563 reputation)

Group: General Forum Members
Points: 563 Visits: 2445
Hi Venki,
Here is the answer to your problem.

http://www.sqlservercentral.com/scripts/Scalar-valued+Functions/61567/

As I understand from your description, you need to do the following modifications to get what you exactly need.

1. The function CalcTimeSinceCreated will have to be modified to take two parameters case as 'task beginning date&time' and 'task ending date&time', instead of one at present

2. I am hardcoding the working hours and weekdays in the functions. You need to modify it to take this information from 2 tables i.e., Holidays and WorkingHours.

If you provide me the exact structure of your two tables and a few rows of the sample data then I may help you in the above two tasks.

Regards,
Mazharuddin

-----------------------------------------------------------
Time Is Money
Calculating the Number of Business Hours Passed since a Point of Time
Calculating the Number of Business Hours Passed Between Two Points of Time

venkatesh-MSBI
venkatesh-MSBI
Grasshopper
Grasshopper (16 reputation)Grasshopper (16 reputation)Grasshopper (16 reputation)Grasshopper (16 reputation)Grasshopper (16 reputation)Grasshopper (16 reputation)Grasshopper (16 reputation)Grasshopper (16 reputation)

Group: General Forum Members
Points: 16 Visits: 117
HI Mazharuddin

I AM VERY MUCH THANKFUL TO YOU FOR YOUR SOLUTION.

I AM WORKING ON THAT NOW.

ONCE AGAIN THANKS


REGARDS
VENKI
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search