Sign in to follow this  
Followers 0
J_Y_C

Network Days

5 posts in this topic

#1 ·  Posted (edited)

In Excel, there is a function called "NETWORKDAYS()" that tells you the difference between two day excluding the weekend. I couldn't find anything like this built into AutoIt so I added my own:

#include <Date.au3>

Func _networkDays($date1, $date2);takes in YYYY/MM/DD
    $dayDiff =_DateDiff('D',$date1,$date2)
    if ($dayDiff>0) Then
        $dt1arr =StringSplit($date1,"/")
        $dt2arr =StringSplit($date2,"/")
        $betweenDays = $dt2arr[3]-$dt1arr[3]
        for $wkendChk = 1 to $betweenDays-1
            If ((_DateToDayOfWeek ( $dt1arr[1], $dt1arr[2], $dt1arr[3]+$wkendChk )=1) or (_DateToDayOfWeek ( $dt1arr[1], $dt1arr[2], $dt1arr[3]+$wkendChk )=7)) then
                $dayDiff-=1
            EndIf
        Next
        Return $dayDiff
    Else
        Return $dayDiff
    EndIf
EndFunc

Func _MMDDYYYYtoYYYYMMDD($d)
    $da = StringSplit($d,"/")
    if ($da[0]=3) Then
        return $da[3] & "/" & $da[1] & "/" & $da[2]
    Else
        SetError(1)
        MsgBox(0,"ERROR","Invalid date format")
    EndIf
EndFunc

Oh, and if you're like me and used to using MM/DD/YYYY instead of YYYY/MM/DD, I included a little function for that also. I hope this is useful to someone!

Edited by J_Y_C

Share this post


Link to post
Share on other sites



Very cool, I've seen other examples of this before, mainly:

Business Days

as the link says, most people know that as Business Days. Yours is still cool, and up-to-date (not sure if the one I posted works with the newest AutoIt, pretty sure yours will however).

Note: Haven't tested either one as of yet (still at work), but the logic and code seems right.

Share this post


Link to post
Share on other sites

Yeah, I don't know why excel calls it "network days", and I didn't know if that was just a term I was ignorant to.

Thanks tho.

Share this post


Link to post
Share on other sites

Yeah, I don't know why excel calls it "network days", and I didn't know if that was just a term I was ignorant to.

The function is called NETWORKDAYS(), which means net work days (The space between net and work is deliberate).

freanir

Share this post


Link to post
Share on other sites

LMAO!!

Thanks freanir, I astound myself on just how dense I can be! That makes perfect sense.. LOL

:whistle:

Share this post


Link to post
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
Sign in to follow this  
Followers 0