MrExcel Message Board

Go Back   MrExcel Message Board > Question Forums > Excel Questions

Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only.

Reply
 
Thread Tools Display Modes
Old Apr 16th, 2002, 11:44 AM   #1
clogteachr
New Member
 
Join Date: Jan 2002
Posts: 4
Default

Mr. Excel,
I've been asked by a friend to help with the automatic calculation of shipping times. His supervisor wants to know the length of time it takes to from date, hour & minute a package was shipped to the date, hour & minute it was delivered EXCLUDING weekends.

How can this be done? I've tried a couple of things, but cannot get the weekends out of it.


Sam Gill CPS
clogteachr is offline   Reply With Quote
Old Apr 16th, 2002, 11:46 AM   #2
Dave Patton
Board Regular
 
Join Date: Feb 2002
Location: Calgary, Alberta Canada
Posts: 2,065
Default


look at NetWorkdays

Returns the number of whole working days between start_date and end_date. Working days exclude weekends and any dates identified in holidays. Use NETWORKDAYS to calculate employee benefits that accrue based on the number of days worked during a specific term.
If this function is not available, run the Setup program to install the Analysis ToolPak. After you install the Analysis ToolPak, you must enable it by using the Add-Ins command on the Tools menu.
Dave Patton is offline   Reply With Quote
Old Apr 16th, 2002, 11:48 AM   #3
Asala42
Board Regular
 
Join Date: Feb 2002
Location: Southfield,MI USA
Posts: 1,027
Default

Try the function: NETWORKDAYS

That will return the number of workdays (excludes weekends) between 2 specified dates. You also can add holidays into the formula - the help file should carry you through it. If you'd like, you can divide the entire formula by 86000 and format the cell as "hh:mm:ss" to get the requested formatting detail.

Hope that helps
Adam
Asala42 is offline   Reply With Quote
Old Apr 16th, 2002, 12:50 PM   #4
clogteachr
New Member
 
Join Date: Jan 2002
Posts: 4
Default

4/16/02 10:00:00 AM 4/16/02 1:00:00 PM 00:00:00

I'm using the formula:
=(NETWORKDAYS(A2,B2))/86000 and I get the 00:00:00 for the anser to the above dates/times.

What is wrong?
clogteachr is offline   Reply With Quote
Old Apr 16th, 2002, 01:08 PM   #5
Tom Schreiner
Board Regular
 
Join Date: Mar 2002
Location: Cincinnati, Ohio, USA
Posts: 6,824
Default

Hi
I wrote a similiar function for net hours worked for someone else.
Modified it to fit in your case.
Place this code in a standard module.
funtion nts - Net Shipping Time
Call it from anywhere in your workbook as such:
Syntax = nst(BeginningDateTime,EndingDateTime)
If shipping date & time were in A2
If recieving date & time were in B2

=nst(A2,B2)

Will display output in hours and minutes.
Does not account for holidays yet.
Let me know if it works for you.
Thanks,
Tom


Option Explicit
'Function to return the actual shipping time excluding weekends
'holidays are unaccounted for
Function nst(StartingTime As Date, EndingTime As Date)
Dim TotalNetHoursWorked
Dim ThisDayEnd As Date
Dim ThisDayBegin As Date
Dim Cntr As Integer

If StartingTime = 0 Then Exit Function
If EndingTime = 0 Then Exit Function
If Format(StartingTime, "DDDD") = "Saturday" Or _
Format(StartingTime, "DDDD") = "Sunday" Then
MsgBox "Starting Date on " & Format(StartingTime, "DDDD") & " is Invalid"
nst = "Invalid Starting Date"
Exit Function
End If
If Format(EndingTime, "DDDD") = "Saturday" Or _
Format(EndingTime, "DDDD") = "Sunday" Then
MsgBox "Ending Date on " & Format(EndingTime, "DDDD") & " is Invalid"
nst = "Invalid Ending Date"
Exit Function
End If
If DateDiff("d", StartingTime, EndingTime) > 365 Then
MsgBox "Out of range - Greater than one year"
nst = "Invalid Ending Time"
Exit Function
End If
ThisDayEnd = StartingTime + 1
If ThisDayEnd > EndingTime Then
TotalNetHoursWorked = DateDiff("n", StartingTime, EndingTime)
GoTo AllDone
End If

TotalNetHoursWorked = DateDiff("n", StartingTime, ThisDayEnd)
For Cntr = 1 To 365
ThisDayBegin = Month(StartingTime + Cntr) & "/" & Day(StartingTime + Cntr) & "/" & _
Year(StartingTime + Cntr)
ThisDayEnd = ThisDayBegin + 1
If ThisDayBegin > EndingTime Then Exit For
If ThisDayEnd > EndingTime Then
If Format(ThisDayEnd, "MMMM") = "Saturday" Then Exit For
TotalNetHoursWorked = TotalNetHoursWorked + DateDiff("n", ThisDayBegin, EndingTime)
Exit For
End If
If Format(ThisDayEnd, "DDDD") <> "Saturday" And _
Format(ThisDayEnd, "DDDD") <> "Sunday" Then _
TotalNetHoursWorked = TotalNetHoursWorked + DateDiff("n", ThisDayBegin, ThisDayEnd)
Next
AllDone:
nst = Int(TotalNetHoursWorked / 60) & " hrs. - " & Round(TotalNetHoursWorked Mod 60) & " min."
End Function


[ This Message was edited by: TsTom on 2002-04-16 12:13 ]
Tom Schreiner is offline   Reply With Quote
Old Apr 16th, 2002, 01:17 PM   #6
clogteachr
New Member
 
Join Date: Jan 2002
Posts: 4
Default

TomTS:
Can you explain where to place this formula.
clogteachr is offline   Reply With Quote
Old Apr 16th, 2002, 01:51 PM   #7
IML
MrExcel MVP
 
Join Date: Feb 2002
Location: Denver, CO
Posts: 1,744
Default

if you'd prefer formulas over vba for this, you could use the ugly:

=IF(NETWORKDAYS(A2,B2)=1,B2-A2,IF(NETWORKDAYS(A2,B2)=2,(1-(A2-INT(A2))+B2-INT(B2)),(NETWORKDAYS(A2,B2)-2)+(1-(A2-INT(A2))+B2-INT(B2))))

apply custom format of [h]:mm to the cell you put this in...

good luck

[ This Message was edited by: IML on 2002-04-16 12:53 ]
IML is offline   Reply With Quote
Old Apr 16th, 2002, 02:01 PM   #8
Asala42
Board Regular
 
Join Date: Feb 2002
Location: Southfield,MI USA
Posts: 1,027
Default

Hey again,

What the heck was I thinking? Ignore that junk I wrote about dividing by 86400 - I frequently convert a time given in #seconds to a time format. My brain must have just short-circuited

BTW, Networkdays outputs whole days for some odd reason (rounded up - that's what I get for not actually trying my own advice). If you still want to go with a formula approach- try something like this:

=NETWORKDAYS(StartDate,EndDate)-(1-((EndDate-StartDate)-ROUNDDOWN(EndDate-StartDate,0)))

Format this as [h]:mm:ss

Should do the trick. Sorry about the earlier post-

Adam
Asala42 is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump


All times are GMT -4. The time now is 08:05 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
All contents Copyright 1998-2012 by MrExcel Consulting.
diabetic desserts recipes recipes Diabetic Soups Holiday Pizza Recipes Popcorn Recipes Recipes For Microwave Pasta Recipes Casserole Recipes Chili Recipes Curry Recipes Crockpot Recipes Apples Recipes Bread Recipes Vegetarian Recipes Vegetable recipes Desserts Recipes Appetizers Ethnic Recipes Meat Dishes Barbecue Recipes Sauces Recipes Marinade Recipes Low Fat Recipes Frugal Gourmet Kitchen Classics Recipes On The Grill Cook Books Seafood Recipes Cajun Recipes Breads Low Fat Low Fat Breads Bread Machine Recipes Yeast Breads Quick Breads Fat Free Vegetarian Salad Recipes Eggplant Recipes Radish Recipes Tomato Recipes Jalapeno Recipes Potato Recipes Lettuce Recipes Cabbage Recipes Beans Ambrosia Recipes Biscotti Recipes Desserts Low Fat Cookie Recipes Cheesecake Recipes Cake Recipes Pie Recipes Muffin Recipes Custard Recipes Best Appetizers Appetizers Low Fat Salsa Recipes Dip Recipes International Recipes Afghan Recipes Alaska Recipes French Recipes German Recipes Greek Recipes Italian Recipes Spanish Recipes Thai Recipes Korean Recipes Chinese Recipes Mexican Recipes Indian Recipes Beef Recipes Pork Pork & Ham Pork Butts Pork Chop Recipes Pork Ribs Rulled Pork Poultry Recipes Stews Recipes Ground Beef Barbecue Grill Barbecue Smoker All Purpose Sauce BBQ Sauce Barbecue Sauce Carolina BBQ Sauce Pickle Recipes Marinades Smoking Low Fat Appetizers & Dips Low Fat Breakfast Low Fat Cakes Low Fat Cheesecakes Low Fat Cookies Low Fat Desserts Low Fat Fish & Seafood Low Fat Meats Low Fat Pasta Low Fat Pies Low Fat Salads Low Fat Sandwiches Low Fat Sauces & Condiments Low Fat Sides Low Fat Soups Low Fat Vegetarian Baker's Dozen Taste of Home Recipe Book Bon Appetit Cookbook Blacktie Cookbook Buster Cook Book Cookbook USA Cook Book Cook Book Sara's Cookbook Sara's Cookbook Appetizers and Dips Poultry recipes Diabetic recipes Holiday recipes Miscellaneous recipes 110 recipes 1986 Usenet cookbook 2900 recipes Cyberrealm recipes Great sysops of world Specialty recipes Ceideburg recipes Cheese recipes Chili recipes Fruits recipes Garlic recipes Great chefs of NY Londontowne recipes Raisins recipes Recipes for kids US Food Vegetarian recipes Bread recipes Drinks Meat Dishes Brisket recipes Caribou recipes Chicken recipes Filet mignons recipes Pork recipes Swordfish recipes Turkey recipes Pasta recipes Uncategorized recipes Ethnic recipes Canada recipes English recipes Ethiopia recipes Germany recipes Greece recipes Mexican recipes Philippines recipes Welsh recipes Microwave recipes Soups recipes Vegetable recipes Asparagus recipes Barley recipes Brown rice recipes Lentil recipes Mushrooms recipes Salads recipes Wild rice Desserts recipes Cakes recipes Chocolate recipes Cookies recipes Ice cream recipes