Find second monday of each month

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
tomoe_uehara
Posts: 213
Joined: 05 Oct 2013, 12:37
Contact:

Re: Find second monday of each month

29 Jan 2014, 15:12

Ah thanks for your useful script kon, I didn't know the original author Image
kon
Posts: 1756
Joined: 29 Sep 2013, 17:11

Re: Find second monday of each month

29 Jan 2014, 15:55

Image Thank you too. Nice modifications. It's much more useful now.
Edit: I also really like your explanation.
just me
Posts: 9459
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: Find second monday of each month

30 Jan 2014, 01:21

zcooler wrote:... This script is going to save me lots of money for unnecessary parkingtickets. I keep forgetting when those damned dates are and it's beginning to be expensive ;)
Thanks for your help! I usually have my car parked on four different streets in the neighbourhood almost all with different dates when parking is forbidden during a timespan of 8hrs each (maintenance day). My plan is to have this script remind me 1 day before the forbidden parking date, so I have a chance to move the vehicle in time and avoid the ticket...
That isn't what was originally asked for in this thread. You don't need to loop through the year to get the occurrence of the weekday for a given date:

Code: Select all

#NoEnv
Ordinals := ["st", "nd", "rd", "th", "th"]
Weekdays := ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]
Tomorrow += 1, Days
FormatTime, WDay, %Tomorrow%, WDay
Occurrence := Ceil(SubStr(Tomorrow, 7, 2) / 7)
MsgBox, 0, Occurrence of Weekday
      , % "Tomorrow is the " . Occurrence . Ordinals[Occurrence] . " " . Weekdays[WDay] . " of the current month."
User avatar
tomoe_uehara
Posts: 213
Joined: 05 Oct 2013, 12:37
Contact:

Re: Find second monday of each month

30 Jan 2014, 12:04

Here's my attempt to develop kon's script further... Image

Code: Select all

;[tomoe] Weekday Calculator v2
Gui, Font, S10, Courier New
Gui, Add, Text, x24 y8 w30 h20, Year
Gui, Add, Edit, x90 y5 w120 h20 vYear Center Number, %A_YYYY%
Gui, Add, Button, x12 y30 w200 h20 gButton1, Add Rules
Gui, Add, Button, x12 y50 w200 h20 gButton2, Restart
Gui, Add, Button, x12 y70 w200 h34 Default gButton3, GO!!
Gui, Add, ListBox, x12 y110 w200 h130 vListBox
Gui, Add, Edit, x12 y230 w200 h240 vResult ReadOnly
; Generated using SmartGUI Creator for SciTE
Gui, Show,, Weekday Calculator
return

Button1:
Gui, 2:Destroy
Gui, 2:Add, Text, x12 y14 w60 h20, Position
Gui, 2:Add, Text, x12 y34 w60 h20, Day
Gui, 2:Add, DropDownList, x72 y10 w100 h20 vNum r5, First||Second|Third|Fourth|Last
Gui, 2:Add, DropDownList, x72 y30 w100 h21 vDayz r7, Sunday||Monday|Tuesday|Wednesday|Thursday|Friday|Saturday
Gui, 2:Add, Button, x12 y60 w70 h30 gAdd Default, OK
Gui, 2:Add, Button, x102 y60 w70 h30 g2GuiClose, Cancel
Gui, 2:Show,, Add Rules
return

Add:
ab++
Gui, 2:Submit
z%ab% = %Num% %Dayz%
GuiControl,1:, ListBox, %Num% %Dayz%|
StringReplace, ac, Num, First, 1
StringReplace, ac, ac, Second, 2
StringReplace, ac, ac, Third, 3
StringReplace, ac, ac, Fourth, 4
StringReplace, ac, ac, Last, 5
StringReplace, ad, Dayz, Sunday, 1
StringReplace, ad, ad, Monday, 2
StringReplace, ad, ad, Tuesday, 3
StringReplace, ad, ad, Wednesday, 4
StringReplace, ad, ad, Thursday, 5
StringReplace, ad, ad, Friday, 6
StringReplace, ad, ad, Saturday, 7
x%ab% := ac
y%ab% := ad
2GuiClose:
Gui, 2:Destroy
return

Button2:
ab:=
GuiControl,1:, ListBox, |
GuiControl,, Result
return

Button3:
Result :=
Gui, Submit, NoHide
Loop, % ab
{
	aa :=
	ba := x%A_Index%
	bb := y%A_Index%
	Date := Year . "0101"
	Last := SubStr(Date, 5, 2)
	while SubStr(Date, 1, 4) = Year {
		FormatTime, WD, % Date, WDay
		if (WD = bb)
		{
			aa++
			if (SubStr(Date, 5, 2) != Last)
			{
				Last := SubStr(Date, 5, 2)
				aa := 1
			}
			if (aa = ba)
			MM := LTrim(SubStr(Date, 5, 2), "0"), Day%MM% := SubStr(Date, 7, 2)
		}
		Date += 1, Days
	}
	ae := z%A_Index%
	Result = %Result%`n[ %ae% ]
	Loop, 12 {
		FormatTime, Month, % Year (A_Index > 9 ? "" : "0") A_Index, MMMM
		Res := Month (StrLen(Month) > 7 ? "" : "`t") "`t" Day%A_Index%
		Result = %Result%`n%Res%
	}
	Result = %Result%`n
	
}
GuiControl,, Result, %Result%
return

ESC::
GuiClose:
ExitApp
Guest10
Posts: 578
Joined: 01 Oct 2013, 02:50

Re: Find second monday of each month

30 Jan 2014, 12:32

thanks, very nice! :ugeek:
zcooler
Posts: 455
Joined: 11 Jan 2014, 04:59

Re: Find second monday of each month

30 Jan 2014, 15:00

just me wrote:That isn't what was originally asked for in this thread. You don't need to loop through the year to get the occurrence of the weekday for a given date...
Greetings just me! Yes, you are right there's no need to loop the whole year. I'm quite fond of the idea to also display the occurrence of the weekday for the whole year in the msgbox though, but didn't mention anything about that in the first post. Thanks for showing me this approach too. MAN, this thread turns out to be the greatest of lessons :D

Thanks guys!
Cheers
Guest10
Posts: 578
Joined: 01 Oct 2013, 02:50

Re: Find second monday of each month

30 Jan 2014, 16:11

i am not sure if you are talking about this?: :ugeek:

Code: Select all

; http://ahkscript.org/boards/viewtopic.php?f=5&t=1680

#SingleInstance FORCE

;[tomoe] Weekday Calculator v2
Gui, Font, S10, Courier New
Gui, Add, Text, x24 y8 w40 h20, Year:
Gui, Add, Edit, x90 y5 w120 h20 vYear Center Number, %A_YYYY%
Gui, Add, Button, x12 y30 w200 h20 gButton1, Add Rules
Gui, Add, Button, x12 y50 w200 h20 gButton2, Restart
Gui, Add, Button, x12 y70 w200 h34 Default gButton3, GO!
Gui, Add, ListBox, x12 y110 w200 h130 vListBox
Gui, Add, Edit, x12 y230 w200 h240 vResult ReadOnly
; Generated using SmartGUI Creator for SciTE
Gui, Show,, Weekday Calculator
return

Button1:
Gui, 2:Destroy
Gui, 2:Add, Text, x12 y14 w60 h20, Position
Gui, 2:Add, Text, x12 y34 w60 h20, Day
Gui, 2:Add, DropDownList, x72 y10 w100 h20 vNum r5, First||Second|Third|Fourth|Last
Gui, 2:Add, DropDownList, x72 y30 w100 h21 vDayz r7, Sunday||Monday|Tuesday|Wednesday|Thursday|Friday|Saturday
Gui, 2:Add, Button, x12 y60 w70 h30 gAdd Default, OK
Gui, 2:Add, Button, x102 y60 w70 h30 g2GuiClose, Cancel
Gui, 2:Show,, Add Rules
return

Add:
ab++
Gui, 2:Submit
z%ab% = %Num% %Dayz%
GuiControl,1:, ListBox, %Num% %Dayz%|
StringReplace, ac, Num, First, 1
StringReplace, ac, ac, Second, 2
StringReplace, ac, ac, Third, 3
StringReplace, ac, ac, Fourth, 4
StringReplace, ac, ac, Last, 5
StringReplace, ad, Dayz, Sunday, 1
StringReplace, ad, ad, Monday, 2
StringReplace, ad, ad, Tuesday, 3
StringReplace, ad, ad, Wednesday, 4
StringReplace, ad, ad, Thursday, 5
StringReplace, ad, ad, Friday, 6
StringReplace, ad, ad, Saturday, 7
x%ab% := ac
y%ab% := ad
2GuiClose:
Gui, 2:Destroy
return

Button2:
ab:=
GuiControl,1:, ListBox, |
GuiControl,, Result
return

Button3:
Result :=
Gui, Submit, NoHide
Loop, % ab
{
    aa :=
    ba := x%A_Index%
    bb := y%A_Index%
    Date := Year . "0101"
    Last := SubStr(Date, 5, 2)
    while SubStr(Date, 1, 4) = Year {
        FormatTime, WD, % Date, WDay
        if (WD = bb)
        {
            aa++
            if (SubStr(Date, 5, 2) != Last)
            {
                Last := SubStr(Date, 5, 2)
                aa := 1
            }
            if (aa = ba)
            MM := LTrim(SubStr(Date, 5, 2), "0"), Day%MM% := SubStr(Date, 7, 2)
        }
        Date += 1, Days
    }
    ae := z%A_Index%
    Result = %Result%`n[ %ae% ]
    Loop, 12 {
        FormatTime, Month, % Year (A_Index > 9 ? "" : "0") A_Index, MMMM
        Res := Month (StrLen(Month) > 7 ? "" : "`t") "`t" Day%A_Index%
        Result = %Result%`n%Res%
    }
    Result = %Result%`n
   
}
MsgBox, 64,, % Result
GuiControl,, Result, %Result%
return

ESC::
GuiClose:
ExitApp

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Google [Bot], SimmoF, uchihito and 227 guests