Hi,

Try the below code.

Sub test()
Dim bdt As Date
Dim edt As Date
Dim Weekends As Integer
  bdt = "02/06/2009 19:44:31"
  edt = "02/09/2009 10:13:41"
  Weekends = GetWeekends(bdt, edt)
  MsgBox ((edt - bdt) * 24) - (Weekends * 24)
End Sub
Function GetWeekends(DateFrom, DateTo)
DF = DateFrom
DT = DateTo

Do Until DF > DT

    WhatDay = Application.WorksheetFunction.Weekday(DF)

    If WhatDay = 7 Then Sat = Sat + 1
    If WhatDay = 1 Then Sun = Sun + 1

    DF = DF + 1
Loop
GetWeekends = Sat + Sun
End Function




On Feb 10, 9:24 pm, mongoose <svma...@kent.edu> wrote:
> Hi, I am looking to automatically exclude weekend hours from time
> interval calculations
> Example of simple calculation including weekends:
>   Begin dt = 02/06/2009 19:44:31
>   End dt = 02/09/2009 10:13:41
>   (End - begin)*24  = 62.48611104 hours
>
> Example of what I want without weekends:
>   Begin dt = 02/06/2009 19:44:31
>   End dt = 02/09/2009 10:13:41
>   (End - begin) * 24 and excluding weekends = 14.48611104 (hours)
>
> I can get 14.48611104  if I subtract 48 to acct for the weekend, but I
> don't always know which dates are weekends and am hoping to identify
> them automatically in my (end - begin) calculation.

--~--~---------~--~----~------------~-------~--~----~
Visit the blog to download Excel tutorials at 
http://www.excel-macros.blogspot.com

To post to this group, send email to excel-macros@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/excel-macros?hl=en

Visit & Join Our Orkut Community at 
http://www.orkut.com/Community.aspx?cmm=22913620

To Learn VBA Macros Please visit http://www.vbamacros.blogspot.com

To see the Daily Excel Tips, Go to:
http://exceldailytip.blogspot.com
 
If you find any spam message in the group, please send an email to Ayush @ 
jainayus...@gmail.com
-~----------~----~----~----~------~----~------~--~---

Reply via email to