Jump to content
Sign in to follow this  
nooneclose

[SOLVED] How do I find every Monday within a date range in Autoit?

Recommended Posts

Is it possible to use Autoit to find every Monday within a date range? An example would be I want to find every Monday between 1/9/19 through 4/9/19. Then Autoit would give me all the dates on which Monday lands between those two dates. 

Sorry but I don't have any code so far. I was wondering if it was even possible. I read the help file and I didn't see a function that could do that. 

Edited by nooneclose

Share this post


Link to post
Share on other sites

Sure, shouldn't be too hard. Here is an example you can study/play with:

#include <date.au3>
$startjuldate = _DateToDayValue(2019,1,9)
$endjuldate = _DateToDayValue(2019,4,9)
Global $iYear, $iMonth, $iDay

For $x =  $startjuldate To $endjuldate
    _DayValueToDate ( $x, $iYear,$iMonth, $iDay )
    if _DateToDayOfWeek($iYear,$iMonth,$iDay) = 2 Then
        ConsoleWrite("Monday " & $iMonth & "/" & $iDay & "/" & $iYear & @CRLF)
    EndIf
Next

Jos


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.
  :)

Share this post


Link to post
Share on other sites

@Jos Thank you again, Jos the code you posted works great. I just have one more question would it be possible to do something like this:

; The starting date
    $startjuldate = _DateToDayValue($StartDate[1])  ;_DateToDayValue(2019,1,9) 
    ; The ending date
    $endjuldate = _DateToDayValue($EndDate[1])  ;_DateToDayValue(2019,4,9) 
    
    Global $iYear, $iMonth, $iDay

    For $Index = $startjuldate To $endjuldate
        _DayValueToDate ( $Index, $iYear, $iMonth, $iDay )
        ; Finds the day based on its numerical value (1 = Sunday)
        If _DateToDayOfWeek($iYear, $iMonth, $iDay) = 2 Then
            ConsoleWrite("Monday " & $iMonth & "/" & $iDay & "/" & $iYear & @CRLF)
        EndIf
    Next

 For this, to work I need the code to be able to read a value in from an array. Is it possible to give a start date and an end date from an array element? 

Is there a function or something that can do this? (I know these array elements won't work here because of the _DateToDayValue calls for more args)

Share this post


Link to post
Share on other sites

@Jos I was able to figure it out using string manipulation. Here is what I have come up with:

$DayIndex = 0

    While $DayIndex < $IndexRows

        ; Gets the Start date from the array
        $Temp = $StartDate[DayIndex]
        $TempStart = StringLeft($Temp, 8)
        $StartTempYear  = StringLeft($TempStart, 4)
        $StartTempMonth = StringMid($TempStart, 5, 2)
        $StartTempDay   = StringRight($TempStart, 2)

        ; Gets the End date from the array
        $Temp = $EndDate[DayIndex]
        $TempEnd = StringLeft($Temp, 8)
        $EndTempYear  = StringLeft($TempEnd, 4)
        $EndTempMonth = StringMid($TempEnd, 5, 2)
        $EndTempDay   = StringRight($TempEnd, 2)

        ; The starting date
        $startjuldate = _DateToDayValue($StartTempYear, $StartTempMonth, $StartTempDay)  ;_DateToDayValue(2019,1,9)
        ; The ending date
        $endjuldate = _DateToDayValue($EndTempYear, $EndTempMonth, $EndTempDay)          ;_DateToDayValue(2019,4,9)

        Global $iYear, $iMonth, $iDay

        For $Index = $startjuldate To $endjuldate
            _DayValueToDate ( $Index, $iYear, $iMonth, $iDay )
            ; Finds the day based on its numerical value (1 = Sunday)
            If _DateToDayOfWeek($iYear, $iMonth, $iDay) = 1 Then
                ConsoleWrite("Sunday " & $iMonth & "/" & $iDay & "/" & $iYear & @CRLF)
            ElseIf _DateToDayOfWeek($iYear, $iMonth, $iDay) = 2 Then
                ConsoleWrite("Monday " & $iMonth & "/" & $iDay & "/" & $iYear & @CRLF)
            ElseIf _DateToDayOfWeek($iYear, $iMonth, $iDay) = 3 Then
                ConsoleWrite("Tuesday " & $iMonth & "/" & $iDay & "/" & $iYear & @CRLF)
            ElseIf _DateToDayOfWeek($iYear, $iMonth, $iDay) = 4 Then
                ConsoleWrite("Wednesday " & $iMonth & "/" & $iDay & "/" & $iYear & @CRLF)
            ElseIf _DateToDayOfWeek($iYear, $iMonth, $iDay) = 5 Then
                ConsoleWrite("Thursday " & $iMonth & "/" & $iDay & "/" & $iYear & @CRLF)
            ElseIf _DateToDayOfWeek($iYear, $iMonth, $iDay) = 6 Then
                ConsoleWrite("Friday " & $iMonth & "/" & $iDay & "/" & $iYear & @CRLF)
            ElseIf _DateToDayOfWeek($iYear, $iMonth, $iDay) = 7 Then
                ConsoleWrite("Saturday " & $iMonth & "/" & $iDay & "/" & $iYear & @CRLF)
            EndIf
        Next

        $DayIndex += 1

    WEnd

There most likely is a better way and if there is please tell me:) anyway thanks again you were a huge help! 

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  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By shelly
      I have to press tab to reach a selected button then double click on that
      Here's my script but its not working:
      WinActivate("Policy Decisions -- Webpage Dialog","")
      Sleep(3000)
      Send("{TAB}")
      Send("{TAB}")
      Send("{TAB}")                    // at this point its working according to my need  but double click is not working
      Mouseclick("Left",510, 320, 2, 0)

    • By TheDcoder
      See this thread for info:
    • By nooneclose
      Why can I not click on either of my input fields?
      #Region ### START Koda GUI section ### Form= Global $Form1 = GUICreate("Form1", 730, 437, 192, 124) ;GUISetFont(14, 800, 0, "MS Sans Serif") GUISetBkColor(0xC0DCC0) Global $Label1 = GUICtrlCreateLabel("Enter your Password. UserName is auto filled", 62, 40, 604, 41, $SS_CENTER) GUICtrlSetFont(-1, 26, 800, 0, "MS Sans Serif") Global $Label2 = GUICtrlCreateLabel("User Name:", 120, 130, 604, 31, $SS_LEFT) GUICtrlSetFont(-1, 20, 800, 0, "MS Sans Serif") Global $Label3 = GUICtrlCreateLabel("Password:", 135, 210, 604, 31, $SS_LEFT) GUICtrlSetFont(-1, 20, 800, 0, "MS Sans Serif") Global $Input1 = GUICtrlCreateInput(@UserName, 274, 130, 185, 32) GUICtrlSetFont(-1, 14, 800, 1, "MS Sans Serif") Global $Input2 = GUICtrlCreateInput("Password", 274, 210, 185, 32, $ES_PASSWORD) GUICtrlSetFont(-1, 14, 800, 0, "MS Sans Serif") Global $OK = GUICtrlCreateButton("OK", 274, 270, 185, 57) GUICtrlSetFont(-1, 20, 800, 0, "MS Sans Serif") GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $OK Global $UserName = GUICtrlRead($Input1) Global $PassWord = GUICtrlRead($Input2) ExitLoop EndSwitch WEnd ; Delete the GUI window GUIDelete()  
    • By cruisepandey
      Hi, 
      I have a string like this : 
      Global $Msga = "urrent directory is /send.  (Submission of file with log number 29381077284 is confirmed)";
      I want to extract the number 29381077284  from the string. I did StringSplit to split based on "(" and then use space to reach there, But it's not a good choice. 
      Can anyone help me with regular expression to find the number from String using AutoIT. TIA
    • By nooneclose
      I want wanting to run multiple tests on my company website. Sadly the process I want to automate requires opening a File Explorer to add an attachment. Is there a way in to automate a Chrome opened File Explorer?
      (I am using webdriver to automate the other 99% of the process just fine. But when I have it click on attach file and chrome opens a file explorer I do not know how to handle it.) 
      Any help would be greatly appreciated. 
×
×
  • Create New...