Jump to content
Sign in to follow this  
lolipop

Help on Datediff minus the weekend

Recommended Posts

lolipop

Anyone have any idea how I can achieve getting the number of days between two dates excluding weekend(Sat & Sun). For example, if I input 1 Jan 2014 til 8 Jan 2014. I will get the number of days as 6 instead of 8? Any advise is appreciated. TIA :)

Share this post


Link to post
Share on other sites
GaRydelaMer

Hi

i've made this function:

#include <Date.au3>

ConsoleWrite(_JoursOuvres("2014/01/01", "2014/01/08") & @LF)

;; Return 6

Func _JoursOuvres($Start_Date, $End_Date)
    Local $DT = $Start_Date, $iCount = 0, $Y, $M, $D
    While $DT <= $End_Date
        $Y = StringRegExpReplace($DT, "(\d+)/.*", "$1")
        $M = StringRegExpReplace($DT, ".*/(\d+)/.*", "$1")
        $D = StringRegExpReplace($DT, ".*/(\d+)", "$1")
        If _DateToDayOfWeek($Y, $M, $D) <> 1 And _DateToDayOfWeek($Y, $M, $D) <> 7 Then
            $iCount += 1
        EndIf
        $DT = _DateAdd("D", 1, $DT)
    WEnd
    Return $iCount
EndFunc

Edit spelling

Edited by GaRydelaMer

Share this post


Link to post
Share on other sites
lolipop

Sorry. My bad for misunderstanding the code. It works perfectly. Thank you very much.

PS: You might want to edit the code. The function(JoursOuvre) is missing a "s" which is causing the code to fail. :)

Edited by lolipop

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.