Calculate difference between 2 date and times with average

I have used the formula:
Start time	End time	
6/9/2007 10:35 AM	6/9/2007 3:30 PM	4:55
	
Formula	Description (Result)	
=Text(b1-a1,"d:h:)  

But when I use the text function, I cannot calculate an average.  Also, if 
you know a way to calculate the difference and exclude weekends...

0
Aeryn635 (2)
12/15/2005 1:21:02 AM
excel.misc 78881 articles. 5 followers. Follow

1 Replies
442 Views

Similar Articles

[PageSpeed] 43

As for excluding weekends, investigate the NETWORKDAYS formula in Help. 

But if your workday is not 24 hours long, and you have holidays to contend
with in addition to weekends, the problem is fairly complex.

Here are the steps:

1. If StartDate and EndDate are on the same date, hours worked = number of
hours from StartTime through EndTime, but correcting for data entry errors
where the a time is earlier than the start of the workday or later than the
end of the workday.

2. If EndDate is the following day, (a) calculate hours worked on StartDate as
StartTime through end of workday. (b) Calculate hours on EndDate = hours from
start of workday through EndTime. Add these 2 times.

3. If EndDate is later than StartDate + 1, (a) calculate hours on StartDate
and EndDate as in Step 2. (b) Then calculate the number of whole workdays
BETWEEN the two dates (i.e. from StartDate + 1 through EndDate - 1, inclusive)
using NETWORKDAYS, then multiply that by the hours in a workday and add the
two together.

The above assumes that StartDate and EndDate are not holidays, but there may
be intervening holidays.

Here is some VBA code that I wrote several years ago to handle this. The
DayStart and DayEnd are hard-coded as 09:00 and 17:00. If that doesn't
correspond with your working hours, you must change those lines marked with
###. It also requires the NETWORKDAYS function in the ATP, so in the VBEditor
you must set a reference to that library (Tools/References). It allows also
for a Holiday list, and the code corrects for data entry errors where your
start or end date is in fact a holiday.

The worksheet formula is simple:

  =NetWorkHours(A1,B1,HolidayList)

where the start date+time are in A1, the end date+time in B1, and HolidayList
is a range listing holidays. If Start Date has no time component, it is
assumed to be the BEGINNING of the workday (9:00 AM as written) rather than
0:00. If End Date has no time components, it is is assumed to be the END of
the workday (5:00 PM as written) rather than 24:00. If StartDate > EndDate you
get an error.

The lines between the lines of tildes should be pasted into a standard module
in your workbook.

'~~~~~
Option Explicit

Const DayStart As Double = 9 / 24  '###
Const DayEnd As Double = 17 / 24   '###
Const FullDay As Double = DayEnd - DayStart

Function NetWorkHours(ByVal Date1 As Double, ByVal Date2 As Double, _
  Optional Holidays As Range = Nothing) As Variant
  'Uses ATP NETWORKDAYS function
  Dim D As Long
  Dim D1 As Long
  Dim D2 As Long
  Dim T1 As Double
  Dim T2 As Double
  Dim Total As Double

  If Date1 > Date2 Then
    NetWorkHours = CVErr(xlErrNum)
    Exit Function
  End If

  SplitDate Date1, D1, T1
  If T1 < 0 Then T1 = DayStart  'no time given

  SplitDate Date2, D2, T2
  If T2 < 0 Then T2 = DayEnd    'no time given

  Total = 0
  If D2 = D1 Then
    Total = NETWORKDAYS(D1, D1, Holidays) * (T2 - T1)
  Else
    If NETWORKDAYS(D1, D1, Holidays) Then Total = DayEnd - T1
    D = NETWORKDAYS(D1 + 1, D2 - 1, Holidays)
    If D > 0 Then Total = Total + D * FullDay
    If NETWORKDAYS(D2, D2, Holidays) Then Total = Total + T2 - DayStart
  End If
  NetWorkHours = Total

End Function

Private Sub SplitDate(DateAndTime As Double, _
  D As Long, T As Double)
  D = Fix(DateAndTime)
  T = DateAndTime - D
  If T <> 0 Then
    If T < DayStart Then T = DayStart
    If T > DayEnd Then T = DayEnd
  Else
    T = -1
  End If
End Sub

'~~~~~


On Wed, 14 Dec 2005 17:21:02 -0800, "Aeryn635"
<Aeryn635@discussions.microsoft.com> wrote:

>I have used the formula:
>Start time	End time	
>6/9/2007 10:35 AM	6/9/2007 3:30 PM	4:55
>	
>Formula	Description (Result)	
>=Text(b1-a1,"d:h:)  
>
>But when I use the text function, I cannot calculate an average.  Also, if 
>you know a way to calculate the difference and exclude weekends...
0
anonymous (74722)
12/15/2005 2:56:02 AM
Reply:

Similar Artilces:

EXCEL 2007 Formula to calculate INTEREST only on a 3 month bridge
I am trying to calculate monthly INTEREST ONLY payment on a short term bridge/swing loan. Assuming an interest rate of 2.75%, paid monthly, Also assuming it will be required for a 3-6 month period, amount approx $500,000. Just switched to Excel 2007 but don't seem to be able to calculate using the formula builder. Not sure if it is compounded daily or monthly. You might want to check out the IPMT function. From the XL help file: IPMT(rate,per,nper,pv,fv,type) Rate is the interest rate per period. Per is the period for which you want to find the interest and must...

Problems with creating a newsletter
I chose the form "Newsletter - email". I have created a 3 page newsletter. Now, I have NO IDEA how to send it out as an email. I do not want to send it as an attachment. I cannot figure out which "save as" format or what I need to do so that i can email this newsletter. Is there a website that goes through how to do this? Am I correct when I say that it has to be html in order for me to send it as email? That is not one of the options. Any help you give me would be greatly appreciated. Thank you, Markis www.adreamforabetterworld.com ...

Meeting updates #2
My users cannot update meetings created when they were on the old email server. I have noticed that the old string is still mapped to the meeting. e.g x400;c=us;a= ;p=Org name;o=exchagne;s=Lastname;g=firstname; Take a look at the following article: 275134 XADM: Cannot Reply to Messages That Are Sent from a User Account That http://support.microsoft.com/?id=275134 The same thing applies to meetings. How did you move them and what version(s) of Exchange? Thanks, Richard Roddy Microsoft Exchange Support This posting is provided "AS IS" with no warranties, and confers no ri...

Changing SQL Server for CRM 1.2
As my SQL server is currently on its last breath I am in the process of moving our CRM 1.2 databases to a new dedicated serever. I have detatched the databases from the old server, copied the files to the server and attached them. I have then gone into CRM deployment manager and changed to the SQL server to the new server. That all appears to work fine, no error messages. But when users try to access the CRM system they get an error and the CRM server event log fills with error messages. A few are listed below: dmLog: Failed to execute the SQL batch in the file sqlbatch.sql. MSCRM P...

How do you turn off/on the "1" or "2" or "+" or "-" view hide/unh.
What is or how do you control, turn on/off the small "1" "2" or "+" "-" hide/unhide view buttons right above the "A" cell? Sometimes shows when I hide columns. Hi 'Data - Goup/Outline' -- Regards Frank Kabel Frankfurt, Germany Seth wrote: > What is or how do you control, turn on/off the small "1" "2" or "+" > "-" hide/unhide view buttons right above the "A" cell? Sometimes > shows when I hide columns. You can toggle them to hide or display with <Ctrl> <8> Usi...

visual basic
Hi, I trying to retrieve values from a table to calculate the 14days average value of a stock closing price. However, i encounter some problem as stated beside the code as follows: Function DaysAvgs() 'Calculate the average value of a given value. Dim db As DAO.Database Dim rst As DAO.Recordset Dim varBookmark As Variant Dim numAve, numDaysAvg As Double Dim intA, intB, lngCount As Integer Set db = CurrentDb 'Open Table Set rst = db.OpenRecordset("SGX Individual Historical", dbOpenTable) rst.MoveFirst Do While Not rst.EOF intA = 1 intB = 0 varBookmark = rst.Bookmark n...

Steps to Share Outlook on 2 different drives
This is a problem created by a dual boot of XPPSP2 on one drive C:\ and Vista on another drive E:\ that I use to format for new builds of Vista on the same box. I want to take my Outlook 2003 in box and folders on two different drives on one box and combine them so that all the emails go to one account and all the folders can be shared or used on each drive. I want to do the same with Outlook Express as well, and since this is an *Outlook newsgroup, I'll just take what I learn here and apply it to the ..dbx folder(s) in it. The idea is to receive email on both drives in one in one...

printing 2 charts on single page
Using Excel 2k, Win 2k I was trying to print to line charts on a single page to demonstrate the corelation between the two data sets. I would like to print in portait mode with one chart on top of page and one on bottom. Excel only seems to offer putting chart 2 on a separate page or embedding it in chart one. I am not very familiar with excel charting capabilites can anyone suggest a resorce? Thanks ...

Oldest date for Duplicate Cust. #
I'm trying to get the oldest date associated with a customer number, and in the Cust# column, i'll have many duplications of the same customer number. Let's say A is "Date", and B is "Cust#". (I won't be able to allow my users to sort the data, so i'll need a formula that returns either the oldest date, or the cell which contains the oldest date.) Any help is much appreciated! Nevermind. I found it using Google/Groups. {=MIN(IF($B$1:$B$10=B1,$A$1:$A$10))} >-----Original Message----- >I'm trying to get the oldest date associated with a...

Date trasfer when importing emails to CRM
When I import old emails into CRM from Outlook they are tagged in CRM with the today's date, the day I imported them. Is there any way to alter this date once in CRM to reflect the actual date of the email? I believe your referring to promoting emails within Outlook. If so, please see this thread: news:5DF7B2F7-B5CE-4FF9-80E3-421D4FE5F500@microsoft.com -- Jason -- This posting is provided "AS IS" with no warranties, and confers no rights. "Eric" <Eric@discussions.microsoft.com> wrote in message news:6CF94DF6-7659-4793-AF6E-439BB480DC29@microsoft.com......

Offline folder problems #2
Hi Guys, Basically I installed Outlook 97 on my office PC which is connect to microsoft exchange server. For some reason all of my messages were copied into offline folders, this causes a problem, whenever I open up outlook I get this message. Upload of offline changes could not be completed you do not have sufficient permission to perform this operation on this object. See the folder contact or see your system administrator. I do not administrator access on my user profile, every time I open outlook it resets everything I have changed (view etc) and gives that error message. How ...

Dates #9
The problem of a date code... I need to address this so that fo example, 5/6/04 can be correctly entered as either 5th of June or 6t of May, depending from where the date emanted. regards -- Message posted from http://www.ExcelForum.com Couldn't you format the cell as mmmm dd, yyyy so that the user sees what date they entered in a non-ambiguous manner right away? Or maybe provide 3 inputs: Month, day, and year. You could combine them elsewhere. "adn4n <" wrote: > > The problem of a date code... I need to address this so that for > example, 5/6/04 can be c...

open two different Access reports
Hi, I was wondering if i can get some help here. I have two different reports that i want to open when a user clicks a button to view the reports for printing. Is there any way of popping them up at the same time in VBA? Thank you in advance Associates wrote: >Hi, > >I was wondering if i can get some help here. I have two different reports >that i want to open when a user clicks a button to view the reports for >printing. Is there any way of popping them up at the same time in VBA? > >Thank you in advance Yes. Call the DoCmd.OpenReport command twic...

VBA to creating autotext entries or quickparts in different catego
I have a VBA application that basically allows people to easily create autotext entiries, move them between machines and use them making comments on assignments. Currently it operates in EXACTLY the same way in Word 2003 and 2007 (using userforms) and I want to keep that as long as possible. You can see the application at http://emarking-assistant.baker-evans.com and either the screen image or the video demos will give you an idea of what I am doing Currently I store all the comments in a long list of autotext entries that is displayed in a field with the value of the entr...

Change the Exchange Virtual Directory to different website
I would like to remove the exchange virtual directory default website and move it another website which is currently redirecting to the website I want to delete. Meaning rather than logon to OWA as http://www.wheresmylunch.com/exchange (current default website) I want to move to http://www.getyourownsandwich,com/exchange. I am using Exchange 2000 server. Rube You would change the host header on the current website. -- Hope that helps, Dan Townsend This posting is provided "AS IS" with no warranties, and confers no rights. Please do not send email to this address, post a reply t...

Receiving Transaction Entry #2
I went into Receiving Transaction Entry to record the receipt of an item. The invoiced price did not agree with the purchase order. I had to add Shipping and adjust the provincial tax. I went to the proper screen to over-ride the calculated tax and the system told me that I couldn't do that because I had not filled in all the BOLD, RED areas. At that point I wanted to close down that screen, but the system would not let me do that either. I could minimize the screen and then I could also see that there wasn't any required information that had not be entered. The only way I c...

Opening pub files created with older Publisher versions #2
I have just upgraded to Publisher 2003 from 2000 and am having trouble with pub files sent to me for our chuch newsletter which is using Publisher 97 The text is not wrapping around graphics boxes. Can I fix this? I really don't want to go back to Pub 200 Thank Richard this is caused by Publisher 97 not been printer independent. Even if you went back to Publisher 2000, unless you have the identical font versions and printer driver you would have issues with formatting. It sounds like the person sending you the file has a garbage HP inkjet printer. Get them to install the HP5P laser p...

Qrp Date functions
Where do I find the various functions to modify the Reports like cast(DatePart(Dd,[Transaction].Time) as nvarchar) and others and what they mean???? Barry Found the information at MSDN Transact-SQL Reference Barry "Barry L" <barryl@eryanjewelers.com> wrote in message news:usd3uP1CIHA.1188@TK2MSFTNGP04.phx.gbl... > Where do I find the various functions to modify the Reports > like cast(DatePart(Dd,[Transaction].Time) as nvarchar) and others > and what they mean???? > > Barry > ...

Associating Multiple Existing Contacts to an Account, Until CRM 2.x
I have racked my pea-sized brain for endless days for a way to associate multiple existing contacts (or accounts) to an account. My client has accounts that have many contacts (or accounts) involved at different stages of acquiring a new account. The logical method would be to add a custom attribute with lookup functionality into the existing CRM contact or account objects but this is not possible with CRM 1.x. The resulting UI would allow an end user to associate different contacts (or accounts) to an account. Example: Account: ABC - AccountPhysician: (existing account or con...

date tracking
I am entering clients into a 2007 Excel spreadsheet. How do I make the entry turn color when 14 days have passed? Gene This is a multi-part message in MIME format. ------=_NextPart_000_0018_01CAC8D4.5688AC60 Content-Type: text/plain; format=flowed; charset="UTF-8"; reply-type=original Content-Transfer-Encoding: 7bit As part of the "client" entries, do you enter the date the client was entered? This would be the key in doing this task. In a cell on the worksheet you could enter the formula for today's date like this =TODAY(). Then use the con...

VCard issue #2
This is a weird problem, but when I send a vcard to someone, it shows up in my sent items as a vcf file, and has a vcard icon on it, but when the recipient gets the VCard, it shows up as msg file, with an envelope icon as the attachment. When I open it, nothing is there - it's empty. I can't find anything regarding this problem on google or MS's website. Anybody have any ideas? Is it a problem with Outlook? Do I need to do a detect and repair, a reinstallation? Thanks for your help! Does the same happen when you send a message to yourself? Is he/she able to see it w...

Some Excel formatting functions taking a long time to work #2
Excel 2000 SP3 When I use some formatting functions for the first time in a session, such as bold, increasing font size etc, it takes up to 30 seconds to work. Meantime Excel is locked up until it completes that formatting call. I suspect faulty DLL? Has anyone experienced this? How to fix (other than a complete re- install) ? Any advice appreciated. Piri On Nov 5, 8:39=A0am, Piri <wiremu.pare...@hotmail.com> wrote: > Excel 2000 SP3 > When I use some formatting functions for the first time in a > session, such as bold, increasing font size etc, it takes =A0up to 30 > secon...

question about Time
How to make the time result for example if it�s ( 1:01 ) or higher shows only as ( 1:00 ) and if it�s Lower like ( 0:59 ) or less it will show the same result in this case ( 0:59 ) Any idea & suggestions. Thanks, almufadda@hotmail.com ------------------------------------------------ ~~ Message posted from http://www.ExcelTip.com/ ~~View and post usenet messages directly from http://www.ExcelForum.com/ Using Ron deBruin's google addin and asking for subject round time, I get http://tinyurl.com/wgua -- Don Guillett SalesAid Software donaldb@281.com "saud" <saud.xgc4...

Short time vs short date
In my form I have a fldOutOfRoom which the user inputs a short time into the field, i.e, 0900. I have the following code in the open event of another form called frmRNnotes: If DateDiff("h", Forms!frmPtDemographicNew!frmVisitNewEdit.Form!OutOfRoom, Now) >= 1 Then Me.cmdRNnotesEdit.Visible = False This code gives the RN one hour to complete a note and then he/she can no longer edit the note. What I want to know is the Short Time format going to let the cmdRNnotesEdit button be visible everyday within one hour of the of the original time? That is, is the short time just a tim...

Time Clock Systems
Does anyone have a recommendation for a time clock system that integrates well with GP? On Oct 5, 10:20 am, kcd <k...@discussions.microsoft.com> wrote: > Does anyone have a recommendation for a time clock system that integrates > well with GP? We just implemented Time Matrix by Business Computers (www.business- computers.com) and are very happy with it. We implemented quickly the hardware wasn't propietary or complicated so we were able to source our own stuff. Troy I can speak highly of Unitime's time and attendance system. They are a relatively low cost solution t...