Jump to content

workday/workweek calculation


dickep
 Share

Recommended Posts

I searched on here but did not find what I wanted to do.

I have a countdown timer that counts down the days (calendar) to a specific date. I have a project due that date but need to calculate using only workdays and/or work weeks. That way I know how much time is really needed to work on a project.

Any help on the calculation would be great.

E

Link to comment
Share on other sites

I searched on here but did not find what I wanted to do.

I have a countdown timer that counts down the days (calendar) to a specific date. I have a project due that date but need to calculate using only workdays and/or work weeks. That way I know how much time is really needed to work on a project.

Any help on the calculation would be great.

E

It's ugly but it works. It calculates workdays assuming that a workday is Monday - Friday. Dates must be entered in the format YYYY/MM/DD

Try it and let me know if this is what you were looking for...

#include <Date.au3>

$example = HowManyWorkDays("2009/10/15", "2009/10/21")

MsgBox(0, "Number of Weekdays", "There are " & $example & " weekdays between the given dates")


Func HowManyWorkDays($sStartDate, $sEndDate)
    Dim $MyDate
    Dim $MyTime

    $myStartDate = $sStartDate
    $myEndDate = $sEndDate
    $countWeekDay = 0

    $CountDays = _DateDiff("d", $myStartDate, $myEndDate)

    For $inc = 0 To $CountDays
        $TempDate = _DateAdd('D', $inc, $myStartDate)
        _DateTimeSplit($TempDate, $MyDate, $MyTime)
        $FileYear = $MyDate[1]
        If $MyDate[2] < 10 Then
            $FileMonth = "0" & $MyDate[2]
        Else
            $FileMonth = $MyDate[2]
        EndIf
        If $MyDate[3] < 10 Then
            $FileDay = "0" & $MyDate[3]
        Else
            $FileDay = $MyDate[3]
        EndIf

        ;Returns Day of the Week Range is 1 to 7 where 1=Sunday
        $iWeekday = _DateToDayOfWeek($FileYear, $FileMonth, $FileDay)
        If $iWeekday > 1 And $iWeekday < 7 Then
            $countWeekDay = $countWeekDay + 1
        EndIf
    Next

    Return $countWeekDay
EndFunc   ;==>HowManyWorkDays
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...