Calculating the number of Saturdays within a time range Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
PuzzledGreatly
Posts: 1303
Joined: 29 Sep 2013, 22:18

Calculating the number of Saturdays within a time range

Post by PuzzledGreatly » 27 Nov 2022, 23:51

Suppose I want to look 26 days from today. How can I calculate how many Saturdays are within that 26 day time period? I tried the following but it didn't work:

Code: Select all

d := A_Now
loop, 26
{
	EnvAdd, d, A_index, days
	formattime, n, d, dddd
	
	msgbox, 4096, %finC%, % d A_tab n
}
I expected to see n change to show the day of the week advancing but it didn't. I don't really get EnvAdd and formattime.

User avatar
Datapoint
Posts: 296
Joined: 18 Mar 2018, 17:06

Re: Calculating the number of Saturdays within a time range

Post by Datapoint » 28 Nov 2022, 00:10

Code: Select all

d := A_Now
loop, 26
{
	d += 1, Days
	FormatTime, DayOfWeek, %d%, WDay
	if (DayOfWeek = 7)
		msgbox % d "`n" DayOfWeek
}

User avatar
PuzzledGreatly
Posts: 1303
Joined: 29 Sep 2013, 22:18

Re: Calculating the number of Saturdays within a time range

Post by PuzzledGreatly » 28 Nov 2022, 00:41

Thanks Datapoint, your solution works

User avatar
flyingDman
Posts: 2817
Joined: 29 Sep 2013, 19:01

Re: Calculating the number of Saturdays within a time range  Topic is solved

Post by flyingDman » 28 Nov 2022, 00:42

try:

Code: Select all

period := 26
msgbox % 1 + floor((period-(7-A_WDay)) / 7)
14.3 & 1.3.7

User avatar
PuzzledGreatly
Posts: 1303
Joined: 29 Sep 2013, 22:18

Re: Calculating the number of Saturdays within a time range

Post by PuzzledGreatly » 20 Jan 2023, 20:52

Thanks, flyingDman, I've just discovered that the solution you proposed works better for what I am doing when the day is an actual Saturday.


Post Reply

Return to “Ask for Help (v1)”