Simucal Posted April 12, 2006 Posted April 12, 2006 Hey guys.. just wrote a CalcBusinessDays function for someone in the Support forum and figured I would post it here in case someone would ever need that again. Maybe someday some form of it could get added to Date.au3? #include <Date.au3> Func _CalcBusinessDays($Date1, $Date2); Dates must be in format YYYY/MM/DD $TempDate = $Date1 While $TempDate <> $Date2 $TempDateArray = StringSplit($TempDate, "/") $TempDateArray[1] = Number($TempDateArray[1]) $TempDateArray[2] = Number($TempDateArray[2]) $TempDateArray[3] = Number($TempDateArray[3]) $DayOfWeek = _DateToDayOfWeek($TempDateArray[1],$TempDateArray[2],$TempDateArray[3]) If $DayOfWeek = 1 Or $DayOfWeek = 7 Then $TempDate = _DateAdd("D",1,$TempDate) Else $r = $r + 1 $TempDate = _DateAdd("D",1,$TempDate) EndIf WEnd ;msgbox(0,"Business Days","Number of business days is: " & $r) Return $r EndFunc AutoIt Scripts:Aimbot: Proof of Concept - PixelSearching Aimbot with several search/autoshoot/lock-on techniques.Sliding Toolbar - Add a nice Sliding Toolbar to your next script. Click the link to see an animation of it in action!FontInfo UDF - Get list of system fonts, or search to see if a particular font is installed.Get Extended Property UDF - Retrieve a files extended properties (e.g., video/image dimensions, file version, bitrate of song/video, etc)
Developers Jos Posted April 12, 2006 Developers Posted April 12, 2006 Couple of issues with your UDF: $R is not defined this gives and error. When the $Date1 is greater than $Date2 the UDF will loop indefinitely. When the dates are far apart, the UDF will be very slow, This can be solve by calculating the numebr of full weeks and only use your logic for the remaining days.. Here is more or less what i mean: Func _CalcBusinessDays($Date1, $Date2); Dates must be in format YYYY/MM/DD Local $TempDate,$dummy Local $Days = Abs(_DateDiff("d",$Date1, $Date2)) ConsoleWrite('@@ Debug(27) : $Days = ' & $Days & @lf & '>Error code: ' & @error & @lf);### Debug Console Local $Weeks = Abs(_DateDiff("w",$Date1, $Date2)) Local $Rest = $Days - ($Weeks * 7) Local $BDays = $Weeks * 5 For $x = 1 To $rest _DateTimeSplit(_DateAdd("D",$x * -1,$Date2),$TempDate,$dummy) $DayOfWeek = _DateToDayOfWeek($TempDate[1],$TempDate[2],$TempDate[3]) If Not ($DayOfWeek = 1 Or $DayOfWeek = 7) Then $BDays = $BDays + 1 EndIf Next Return $BDays EndFunc SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past.
Simucal Posted April 12, 2006 Author Posted April 12, 2006 (edited) Excellent JdeB. I'm still very new at AutoIt.. and it is great to see how I could do things in a more refined manner. I just saw the $r variable not being declared, I had taken it out of the post that I made earlier. Thanks for pointing this out. Thanks again, Simucal Edited April 12, 2006 by Simucal AutoIt Scripts:Aimbot: Proof of Concept - PixelSearching Aimbot with several search/autoshoot/lock-on techniques.Sliding Toolbar - Add a nice Sliding Toolbar to your next script. Click the link to see an animation of it in action!FontInfo UDF - Get list of system fonts, or search to see if a particular font is installed.Get Extended Property UDF - Retrieve a files extended properties (e.g., video/image dimensions, file version, bitrate of song/video, etc)
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now