Hobbyist Posted August 15, 2017 Share Posted August 15, 2017 I am desiring to be able to check if a given date is between two dates (inclusively). After reading the help file I still don't grasp it. I am not looking to return the number of days between two dates. I also want to consider dates ranges than exist between two different months. So a range would be a single month or overlapping months. I used date picker to assign a start date and end date. The button would compare those dates to the range. Any help to get me started in the right direction would be appreciated Hobbyist expandcollapse popup#Region ;**** Directives created by AutoIt3Wrapper_GUI **** ;#AutoIt3Wrapper_Run_Au3Stripper=y ;#Au3Stripper_Parameters= /StripUnusedVars=0/1 /SV=0/1 #AutoIt3Wrapper_Outfile=L:\Dash Board.exe #AutoIt3Wrapper_Run_Tidy=y ;#AutoIt3Wrapper_Au3Check_Parameters =-w 5 ; -q -d -w 1 -w 2 -w 3 -w- 4 -w 5 -w 6 -w- 7 #AutoIt3Wrapper_Au3Check_Parameters = -q -d -w 1 -w 2 -w 3 -w- 4 -w 5 -w 6 -w- 7 #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** ;<<<<<<<<<<<<<<<<<<<<<<<< #include <Array.au3> #include <Date.au3> #include <GUIConstantsEx.au3> #include <Misc.au3> #include <MsgBoxConstants.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <GuiDateTimePicker.au3> #include <ButtonConstants.au3> ;<<<<<<<<<<<< Local $main = GUICreate(" Dash Board", 680, 515, 150, 100) Local $Button12 = GUICtrlCreateButton("Date File", 10, 60, 158, 33) ;GUICtrlSetState($Button12, $GUI_DISABLE) GUICtrlSetFont(-1, 8.5, 800, 0, "Verdana") ;GUICtrlSetColor(-1, 0xFF0000) ;GUICtrlSetBkColor(-1, 0xE3E3E3) Local $CardStart = GUICtrlCreateRadio("Start:", 475, 10, 55, 20) GUICtrlSetFont($CardStart, 8.5, 800, 0, "Verdana") Local $Labelstart = GUICtrlCreateLabel("N O N E", 560, 11, 80, 20, $SS_LEFT) GUICtrlSetFont(-1, 8.5, 800, 0, "Verdana") GUICtrlSetState($CardStart, $GUI_enABLE) Local $CardEnd = GUICtrlCreateRadio("End:", 475, 27, 50, 20) GUICtrlSetFont($CardEnd, 8.5, 800, 0, "Verdana") Local $Labelend = GUICtrlCreateLabel("N O N E", 560, 29, 80, 20, $SS_LEFT) GUICtrlSetFont(-1, 8.5, 800, 0, "Verdana") GUICtrlSetState($CardEnd, $GUI_enABLE) Global $hdate = GUICtrlCreateDate(_NowCalcDate(), 357, 28, 100, 16, $WS_BORDER) ;465, 28, 100, 16, $WS_BORDER) GUICtrlSetState($hdate, $GUI_show) Local $hWndDate = ControlGetHandle($main, "", $hdate) _GUICtrlDTP_SetFormat($hWndDate, "MM/dd/yyyy") ;//////////////// Global $CardDate Global $CardDate1 ;start Global $CardDate2 ;end GUISetState(@SW_SHOW) While 1 Local $iMsg = GUIGetMsg() Switch $iMsg Case $GUI_EVENT_CLOSE Exit Case $Button12 MsgBox($MB_SYSTEMMODAL, "Information>>>>", "$ABC = " & $CardDate & " is equal to start/end or inbetween ") ; I don't understand how to compare today's date to the start/end, the following lines I know are not correct $CardDate = today() If $CardDate >= $CardDate1 And $CardDate <= $CardDate2 Then MsgBox($MB_SYSTEMMODAL, "Information>>>>", "$ABC = " & $CardDate & " is equal to start/end or inbetween ") EndIf Case $hdate If GUICtrlRead($CardStart) = 1 Then GUICtrlSetState($hdate, $GUI_enABLE) Local $1stdate = GUICtrlRead($hdate) $CardDate1 = $1stdate ;GUICtrlRead($hdate) GUICtrlSetData($Labelstart, $CardDate1) EndIf If GUICtrlRead($CardEnd) = 1 Then GUICtrlSetState($hdate, $GUI_enABLE) Local $2nddate = GUICtrlRead($hdate) $CardDate2 = $2nddate ; GUICtrlRead($hdate) GUICtrlSetData($Labelend, $CardDate2) EndIf EndSwitch WEnd Func today() ;Return the current date in mm/dd/yyyy form Return (@MON & "-" & @MDAY & "-" & @YEAR) EndFunc ;==>today Link to comment Share on other sites More sharing options...
Danp2 Posted August 15, 2017 Share Posted August 15, 2017 Have you checked out the _DateDIff function? You should be able to use it to compare the date to the start/end date range and use the result to determine if it is within the desired range. Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
Hobbyist Posted August 15, 2017 Author Share Posted August 15, 2017 I looked at it but don't see how it helps my issue. That returns: D = Difference in days between the given dates M = Difference in months between the given dates Y = Difference in years between the given dates w = Difference in Weeks between the given dates h = Difference in hours between the given dates n = Difference in minutes between the given dates s = Difference in seconds between the given dates I can input my start and end date range from the date picker, but I am not looking to find the difference between those two dates. So I don't know how the Diff can help. Link to comment Share on other sites More sharing options...
mikell Posted August 15, 2017 Share Posted August 15, 2017 55 minutes ago, Hobbyist said: So I don't know how the Diff can help. You might just check if Diff is >0, <0 or =0 For comparing dates, "D" is the unit to use. This is based on the helpfile example #include <Date.au3> Local $iDateCalc = _DateDiff('D', "1970/01/01", _NowCalc()) MsgBox(0, "", "Number of seconds: " & $iDateCalc) ; reverse Local $iDateCalc = _DateDiff('D', _NowCalc(), "1970/01/01") MsgBox(0, "", "Number of seconds: " & $iDateCalc) Link to comment Share on other sites More sharing options...
Danp2 Posted August 15, 2017 Share Posted August 15, 2017 1 hour ago, Hobbyist said: So I don't know how the Diff can help. What @mikell said. Here's a simple example -- #include <Date.au3> #include <MsgBoxConstants.au3> ; Calculated the number of days between dates Local $sToday = _NowCalc() Local $sNewDate = _DateAdd('d', 5, _NowCalcDate()) Local $iDateCalc = _DateDiff('D', $sNewDate, $sToday) MsgBox($MB_SYSTEMMODAL, "", "Number of days between: " & $iDateCalc) $iDateCalc = _DateDiff('D', $sToday, $sNewDate) MsgBox($MB_SYSTEMMODAL, "", "Number of days between: " & $iDateCalc) So by passing the values in the proper order, you can check to see if one date occurs before, after, or is equal to another date. Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
mikell Posted August 15, 2017 Share Posted August 15, 2017 2 hours ago, Hobbyist said: how the Diff can help Hey it's a difference Basic maths : x > y <=> x - y > 0 Link to comment Share on other sites More sharing options...
Gianni Posted August 16, 2017 Share Posted August 16, 2017 A small function to check if a date falls between 2 others #include <date.au3> MsgBox(0, "Check if between", _dateIsBetween(_NowCalc(), "2017/01/01", "2017/12/31")) ; are we in 2017 ; returns True if Date0 is between Date1 and Date2 (inclusive) ; (Date1 and date 2 can be reversed without problems) ; Dates format is "YYYY/MM/DD" ; $sDate0: Date to be checked ; $dDate1 and $dDate1: the bounds of the period (in any order) Func _dateIsBetween($sDate0, $sDate1, $sDate2) Local $aMyTime Local $aDate[3], $aJulian[3] _DateTimeSplit($sDate0, $aDate[0], $aMyTime) _DateTimeSplit($sDate1, $aDate[1], $aMyTime) _DateTimeSplit($sDate2, $aDate[2], $aMyTime) $aJulian[0] = _DateToDayValue(($aDate[0])[1], ($aDate[0])[2], ($aDate[0])[3]) $aJulian[1] = _DateToDayValue(($aDate[1])[1], ($aDate[1])[2], ($aDate[1])[3]) $aJulian[2] = _DateToDayValue(($aDate[2])[1], ($aDate[2])[2], ($aDate[2])[3]) Local $iNdx1 = 1 + ($aJulian[1] > $aJulian[2]) Local $iNdx2 = 2 - ($aJulian[1] > $aJulian[2]) Return ($aJulian[0] >= $aJulian[$iNdx1]) And ($aJulian[0] <= $aJulian[$iNdx2]) EndFunc ;==>_dateIsBetween Chimp small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt.... Link to comment Share on other sites More sharing options...
mikell Posted August 16, 2017 Share Posted August 16, 2017 #include <date.au3> MsgBox(0, "Check if between", _dateIsBetween(_NowCalc(), "2017/01/01", "2017/12/31")) ; are we in 2017 Func _dateIsBetween($sDate0, $sDate1, $sDate2) Local $date0 = StringReplace($sDate0, "/", ""), $date1 = StringReplace($sDate1, "/", ""), $date2 = StringReplace($sDate2, "/", "") Return (($date0 >= $date1) And ($date0 <= $date2)) ? "yes" : "nope" EndFunc ;==>_dateIsBetween Hobbyist and kylomas 2 Link to comment Share on other sites More sharing options...
Hobbyist Posted August 16, 2017 Author Share Posted August 16, 2017 @Danp2 @mikell @chimp Here is my script attempting the suggestion of using 0 comparison. I had done this before reading the last post by mikell and chimp. I am going to try both of your new suggestions as well and I thank you. Would you expandcollapse popup;~ #Region ;**** Directives created by AutoIt3Wrapper_GUI **** ;~ ;#AutoIt3Wrapper_Run_Au3Stripper=y ;~ ;#Au3Stripper_Parameters= /StripUnusedVars=0/1 /SV=0/1 ;~ #AutoIt3Wrapper_Outfile=L:\Dash Board.exe ;~ #AutoIt3Wrapper_Run_Tidy=y ;~ ;#AutoIt3Wrapper_Au3Check_Parameters =-w 5 ; -q -d -w 1 -w 2 -w 3 -w- 4 -w 5 -w 6 -w- 7 ;~ #AutoIt3Wrapper_Au3Check_Parameters = -q -d -w 1 -w 2 -w 3 -w- 4 -w 5 -w 6 -w- 7 ;~ #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** ;<<<<<<<<<<<<<<<<<<<<<<<< #include <Array.au3> #include <Date.au3> #include <GUIConstantsEx.au3> #include <Misc.au3> #include <MsgBoxConstants.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <GuiDateTimePicker.au3> #include <ButtonConstants.au3> ;<<<<<<<<<<<< Local $main = GUICreate(" Dash Board", 680, 515, 150, 100) Local $Button12 = GUICtrlCreateButton("Date File", 10, 60, 158, 33) GUICtrlSetFont(-1, 8.5, 800, 0, "Verdana") Local $CardStart = GUICtrlCreateRadio("Start:", 475, 10, 55, 20) GUICtrlSetFont($CardStart, 8.5, 800, 0, "Verdana") Local $Labelstart = GUICtrlCreateLabel("N O N E", 560, 11, 80, 20, $SS_LEFT) GUICtrlSetFont(-1, 8.5, 800, 0, "Verdana") GUICtrlSetState($CardStart, $GUI_enABLE) Local $CardEnd = GUICtrlCreateRadio("End:", 475, 27, 50, 20) GUICtrlSetFont($CardEnd, 8.5, 800, 0, "Verdana") Local $Labelend = GUICtrlCreateLabel("N O N E", 560, 29, 80, 20, $SS_LEFT) GUICtrlSetFont(-1, 8.5, 800, 0, "Verdana") GUICtrlSetState($CardEnd, $GUI_enABLE) Global $hdate = GUICtrlCreateDate(_NowCalcDate(), 357, 28, 100, 16, $WS_BORDER) ;465, 28, 100, 16, $WS_BORDER) GUICtrlSetState($hdate, $GUI_show) Local $hWndDate = ControlGetHandle($main, "", $hdate) ;_GUICtrlDTP_SetFormat($hWndDate, "MM/dd/yyyy") ;//////////////// _GUICtrlDTP_SetFormat($hWndDate, "yyyy/MM/dd") ;//////////////// Global $CardDate Global $CardDate1 ;start Global $CardDate2 ;end GUISetState(@SW_SHOW) While 1 Local $iMsg = GUIGetMsg() Switch $iMsg Case $GUI_EVENT_CLOSE Exit Case $Button12 ;Check today's date againt a date range assigned by radiobuttons via datepicker $CardDate = today() local $iDateCalc if _DateDiff('D', $CardDate1,$CardDate) > 0 and _DateDiff('D', $CardDate2,$CardDate) < 0 then MsgBox($MB_SYSTEMMODAL, ""& $CardDate1 & " " &$CardDate2 , "start/end date " &$CardDate1 & " Date In Range: " & $iDateCalc) Else MsgBox($MB_SYSTEMMODAL, ""& $CardDate1 & " " &$CardDate2 , "start/end date " &$CardDate1 & " Date NOT In Range: " & $iDateCalc) EndIf Case $hdate If GUICtrlRead($CardStart) = 1 Then GUICtrlSetState($hdate, $GUI_enABLE) Local $1stdate = GUICtrlRead($hdate) $CardDate1 = $1stdate ;GUICtrlRead($hdate) GUICtrlSetData($Labelstart, $CardDate1) EndIf If GUICtrlRead($CardEnd) = 1 Then GUICtrlSetState($hdate, $GUI_enABLE) Local $2nddate = GUICtrlRead($hdate) $CardDate2 = $2nddate ; GUICtrlRead($hdate) GUICtrlSetData($Labelend, $CardDate2) EndIf EndSwitch WEnd Func today() ; Return (@YEAR & "/" &@MON & "/" & @MDAY) EndFunc ;==>today also look at my new script (Button12 is where the change is) and shoot holes in or tell me its weakness? I can learn much from you and become better at scripting. Link to comment Share on other sites More sharing options...
Danny35d Posted August 16, 2017 Share Posted August 16, 2017 (edited) Give it a try I use the following functions _DateTimeSplit() and _DateToDayValue() to convert the Dates to decimal and then compare if is between the dates. expandcollapse popup;~ #Region ;**** Directives created by AutoIt3Wrapper_GUI **** ;~ ;#AutoIt3Wrapper_Run_Au3Stripper=y ;~ ;#Au3Stripper_Parameters= /StripUnusedVars=0/1 /SV=0/1 ;~ #AutoIt3Wrapper_Outfile=L:\Dash Board.exe ;~ #AutoIt3Wrapper_Run_Tidy=y ;~ ;#AutoIt3Wrapper_Au3Check_Parameters =-w 5 ; -q -d -w 1 -w 2 -w 3 -w- 4 -w 5 -w 6 -w- 7 ;~ #AutoIt3Wrapper_Au3Check_Parameters = -q -d -w 1 -w 2 -w 3 -w- 4 -w 5 -w 6 -w- 7 ;~ #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** ;<<<<<<<<<<<<<<<<<<<<<<<< #include <Array.au3> #include <Date.au3> #include <GUIConstantsEx.au3> #include <Misc.au3> #include <MsgBoxConstants.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <GuiDateTimePicker.au3> #include <ButtonConstants.au3> ;<<<<<<<<<<<< Local $main = GUICreate(" Dash Board", 680, 515, 150, 100) Local $Button12 = GUICtrlCreateButton("Date File", 10, 60, 158, 33) GUICtrlSetFont(-1, 8.5, 800, 0, "Verdana") Local $CardStart = GUICtrlCreateRadio("Start:", 475, 10, 55, 20) GUICtrlSetFont($CardStart, 8.5, 800, 0, "Verdana") Local $Labelstart = GUICtrlCreateLabel("N O N E", 560, 11, 80, 20, $SS_LEFT) GUICtrlSetFont(-1, 8.5, 800, 0, "Verdana") GUICtrlSetState($CardStart, $GUI_enABLE) Local $CardEnd = GUICtrlCreateRadio("End:", 475, 27, 50, 20) GUICtrlSetFont($CardEnd, 8.5, 800, 0, "Verdana") Local $Labelend = GUICtrlCreateLabel("N O N E", 560, 29, 80, 20, $SS_LEFT) GUICtrlSetFont(-1, 8.5, 800, 0, "Verdana") GUICtrlSetState($CardEnd, $GUI_enABLE) Global $hdate = GUICtrlCreateDate(_NowCalcDate(), 357, 28, 100, 16, $WS_BORDER) ;465, 28, 100, 16, $WS_BORDER) GUICtrlSetState($hdate, $GUI_show) Local $hWndDate = ControlGetHandle($main, "", $hdate) ;_GUICtrlDTP_SetFormat($hWndDate, "MM/dd/yyyy") ;//////////////// _GUICtrlDTP_SetFormat($hWndDate, "yyyy/MM/dd") ;//////////////// Global $CardDate Global $CardDate1 ;start Global $CardDate2 ;end Local $aDate, $aTime GUISetState(@SW_SHOW) While 1 Local $iMsg = GUIGetMsg() Switch $iMsg Case $GUI_EVENT_CLOSE Exit Case $Button12 ;Check today's date againt a date range assigned by radiobuttons via datepicker $CardDate = today() Local $iDateCalc _DateTimeSplit($CardDate1, $aDate, $aTime) $TempDate1 = _DateToDayValue($aDate[1], $aDate[2], $aDate[3]) _DateTimeSplit($CardDate2, $aDate, $aTime) $TempDate2 = _DateToDayValue($aDate[1], $aDate[2], $aDate[3]) If $CardDate >= $TempDate1 And $CardDate <= $TempDate2 Then MsgBox($MB_SYSTEMMODAL, "" & $CardDate1 & " " & $CardDate2, "start/end date " & $CardDate1 & " Date In Range: " & $iDateCalc) Else MsgBox($MB_SYSTEMMODAL, "" & $CardDate1 & " " & $CardDate2, "start/end date " & $CardDate1 & " Date NOT In Range: " & $iDateCalc) EndIf Case $hdate If GUICtrlRead($CardStart) = 1 Then GUICtrlSetState($hdate, $GUI_enABLE) $1stdate = GUICtrlRead($hdate) $CardDate1 = $1stdate ;GUICtrlRead($hdate) GUICtrlSetData($Labelstart, $CardDate1) EndIf If GUICtrlRead($CardEnd) = 1 Then GUICtrlSetState($hdate, $GUI_enABLE) $2nddate = GUICtrlRead($hdate) $CardDate2 = $2nddate ; GUICtrlRead($hdate) GUICtrlSetData($Labelend, $CardDate2) EndIf EndSwitch WEnd Func today() ; Return (_DateToDayValue(@YEAR, @MON, @MDAY)) EndFunc ;==>today Edited August 16, 2017 by Danny35d AutoIt Scripts:NetPrinter - Network Printer UtilityRobocopyGUI - GUI interface for M$ robocopy command line Link to comment Share on other sites More sharing options...
Hobbyist Posted August 17, 2017 Author Share Posted August 17, 2017 @ Danny35d Thanks for the example. I will give it a try. Always interested in learning how to solve an issue in scripting. Hobbyist Link to comment Share on other sites More sharing options...
Gianni Posted August 17, 2017 Share Posted August 17, 2017 On 16/8/2017 at 2:44 PM, mikell said: #include <date.au3> MsgBox(0, "Check if between", _dateIsBetween(_NowCalc(), "2017/01/01", "2017/12/31")) ; are we in 2017 Func _dateIsBetween($sDate0, $sDate1, $sDate2) Local $date0 = StringReplace($sDate0, "/", ""), $date1 = StringReplace($sDate1, "/", ""), $date2 = StringReplace($sDate2, "/", "") Return (($date0 >= $date1) And ($date0 <= $date2)) ? "yes" : "nope" EndFunc ;==>_dateIsBetween #include <date.au3> MsgBox(0, "Check if between", _dateIsBetween(_NowCalcDate(), "2017/01/01", "2017/12/31")) ; are we in 2017 Func _dateIsBetween($sDate0, $sDate1, $sDate2) Return($sDate0 >= $sDate1) And ($sDate0 <= $sDate2) EndFunc ;==>_dateIsBetween Chimp small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt.... Link to comment Share on other sites More sharing options...
mikell Posted August 17, 2017 Share Posted August 17, 2017 Right, _NowCalcDate() is cleaner But personally I'd keep the StringReplace's . Not sure, doesn't AutoIt convert internally to Number before numeric comparison ? Msgbox(0,"", Number("2017/01/01") ) Link to comment Share on other sites More sharing options...
Gianni Posted August 17, 2017 Share Posted August 17, 2017 29 minutes ago, mikell said: ...... Not sure, doesn't AutoIt convert internally to Number before numeric comparison ? .... ... That post #12 was just for fun , .... aniway... from a quick search seems that with comparison operators there is not conversion from strings to numbers: from the "Language Reference - Operators" at the "Comparison operators" session: "Strings are compared lexicographically even if the contents of the string happen to be numeric" and from "Lexicographical order" in Wikipedia in the "Numeral systems and dates" session: ".... Another example of a non-dictionary use of lexicographical ordering appears in the ISO 8601 standard for dates, which expresses a date as YYYY-MM-DD. This formatting scheme has the advantage that the lexicographical order on sequences of characters that represent dates coincides with the chronological order: an earlier date is smaller in the lexicographical order than a later date. This date ordering makes computerized sorting of dates easier by avoiding the need for a separate sorting algorithm." .... p.s. learned something new ,,,, mikell 1 Chimp small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt.... Link to comment Share on other sites More sharing options...
Hobbyist Posted August 17, 2017 Author Share Posted August 17, 2017 Thank you, thank you, thank you all. You are all very talented in your scripting. I like Mikell's solution the best for this reason - less lines of script. The newbie in me says less lines can be a good thing as long as the results are accomplished. But also the other solutions prompted me to go read more about the terms in them. Again thanks, you all are terrific. Hobbyist Link to comment Share on other sites More sharing options...
Malkey Posted August 18, 2017 Share Posted August 18, 2017 This example allows for different date formats and different date separators. Local $InBetweenDate = @YEAR & "/" & @MON & "/" & @MDAY ; "1/6/2017" Local $FirstDate = "4.5.2017" Local $LastDate = "11-12-2017" MsgBox(0, "Results", _ $InBetweenDate & " is " & _ (_IsDateBetween($InBetweenDate, $FirstDate, $LastDate, 0, 2) ? "" : "not") & _ " between " & $FirstDate & " and " & $LastDate & ".") ; $iFormatTestDate and $Format : 0 for input dates format "YYYY/MM/DD"; or, ; 1 for input dates format "MM/DD/YYYY"; or, ; 2 for input dates format "DD/MM/YYYY". ; Where date divider can be "/", "-", or ".". Func _IsDateBetween($TestDate, $StartDate, $EndDate, $iFormatTestDate = 0, $iFormat = 0) Local $aConvert[3] = [ _ "StringFormat('%s%02s%02s','\1', '\2', '\3')", _ ; "YYYY/[M]M/[D]D" to YYYYMMDD "StringFormat('%s%02s%02s','\3', '\1', '\2')", _ ; "[M]M/[D]D/YYYY" to YYYYMMDD "StringFormat('%s%02s%02s','\3', '\2', '\1')"] ; "[D]D/[M]M/YYYY" to YYYYMMDD Local $TDate = Execute(StringRegExpReplace($TestDate, "(\d+)[/\-\.](\d+)[/\-\.](\d+)", $aConvert[$iFormatTestDate])) Local $SDate = Execute(StringRegExpReplace($StartDate, "(\d+)[/\-\.](\d+)[/\-\.](\d+)", $aConvert[$iFormat])) Local $EDate = Execute(StringRegExpReplace($EndDate, "(\d+)[/\-\.](\d+)[/\-\.](\d+)", $aConvert[$iFormat])) ;ConsoleWrite($SDate & " " & $TDate & " " & $EDate & @CRLF) Return ($TDate > $SDate And $TDate < $EDate ? 1 : 0) EndFunc ;==>_IsDateBetween Gianni 1 Link to comment Share on other sites More sharing options...
Gianni Posted August 18, 2017 Share Posted August 18, 2017 (edited) Hi @Malkey, why you exclude the starting and ending dates from the check? if you check a test date that is equal to the starting or ending date of the range it is considered not in between. (is this (not inclusive) a wanted behaviour?) Also, I propose a little variation to your script so that you can invert starting and ending date of the range to your pleasure without affecting the final result (as it should be .... or not?). Local $InBetweenDate = @YEAR & "/" & @MON & "/" & @MDAY ; "1/6/2017" Local $FirstDate = "4.5.2017" Local $LastDate = "11-12-2017" MsgBox(0, "Results", _ $InBetweenDate & " is " & _ (_IsDateBetween($InBetweenDate, $FirstDate, $LastDate, 0, 2) ? "" : "not") & _ " between " & $FirstDate & " and " & $LastDate & ".") ; $iFormatTestDate and $Format : 0 for input dates format "YYYY/MM/DD"; or, ; 1 for input dates format "MM/DD/YYYY"; or, ; 2 for input dates format "DD/MM/YYYY". ; Where date divider can be "/", "-", or ".". Func _IsDateBetween($TestDate, $StartDate, $EndDate, $iFormatTestDate = 0, $iFormat = 0) Local $aConvert[3] = [ _ "StringFormat('%s%02s%02s','\1', '\2', '\3')", _ ; "YYYY/[M]M/[D]D" to YYYYMMDD "StringFormat('%s%02s%02s','\3', '\1', '\2')", _ ; "[M]M/[D]D/YYYY" to YYYYMMDD "StringFormat('%s%02s%02s','\3', '\2', '\1')"] ; "[D]D/[M]M/YYYY" to YYYYMMDD Local $aDates[3] = [ _ Execute(StringRegExpReplace($StartDate, "(\d+)[/\-\.](\d+)[/\-\.](\d+)", $aConvert[$iFormat])), _ ; ....... [0] Starting Date Execute(StringRegExpReplace($EndDate, "(\d+)[/\-\.](\d+)[/\-\.](\d+)", $aConvert[$iFormat])), _ ; ......... [1] Ending Date Execute(StringRegExpReplace($TestDate, "(\d+)[/\-\.](\d+)[/\-\.](\d+)", $aConvert[$iFormatTestDate]))] ; .. [2] Test Date Local $bNdx0 = $aDates[0] > $aDates[1], $bNdx1 = Not($bNdx0) ; arrange index 0 and 1 Return $aDates[2] >= $aDates[$bNdx0] And $aDates[2] <= $aDates[$bNdx1] EndFunc ;==>_IsDateBetween p.s. (just for the record) Here an handy udf by @Melba23 to convert dates in various formats) : https://www.autoitscript.com/forum/topic/154684-date_time_convert-bugfix-version-27-may-15/ Edited August 18, 2017 by Chimp Chimp small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt.... Link to comment Share on other sites More sharing options...
AdamUL Posted August 18, 2017 Share Posted August 18, 2017 (edited) You could use the "_IsBetween" functions in my Date and Time UDF. Adam Edited August 18, 2017 by AdamUL Link to comment Share on other sites More sharing options...
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