# Weekdates from _WeekNumberISO()

## Recommended Posts

I have a program where I use the weeknumber to choose a period of time. One "Gui change" is equal to one week. I want to be able to get the Monday, Tuesday, Wednesday, Thursday and Friday dates for a week given to the function. For example in this function, it checks for given weeks:

```Func WeekCheck(\$Input)
If \$Input = 8 Or \$Input = 17 Or \$Input = 4 Or \$Input = 13 Or \$Input = 22 Then
One()
ElseIf \$Input = 2 Or \$Input = 11 Or \$Input = 19 Then
Two()
ElseIf \$Input = 7 Then
Three()
ElseIf \$Input = 24 Then
Extra()
Else
Sleep(1)
EndIf
EndFunc   ;==>WeekCheck```

The \$Input is a weeknumber which determines the rest.
I now have this function:

```Func LabelCheck(\$Input)
If \$Input = 14 Then \$Label = Label("31.03", "01.04", "02.04", "03.04", "04.04")
If \$Input = 15 Then \$Label = Label("07.04", "08.04", "09.04", "10.04", "11.04")
If \$Input = 16 Then \$Label = Label("14.04", "15.04", "16.04", "17.04", "18.04")
If \$Input = 17 Then \$Label = Label("21.04", "22.04", "23.04", "24.04", "25.04")
If \$Input = 18 Then \$Label = Label("28.04", "29.04", "30.04", "01.05", "02.05")
If \$Input = 19 Then \$Label = Label("05.05", "06.05", "07.05", "08.05", "09.05")
If \$Input = 20 Then \$Label = Label("12.05", "13.05", "14.05", "15.05", "16.05")
If \$Input = 21 Then \$Label = Label("19.05", "20.05", "21.05", "22.05", "23.05")
If \$Input = 22 Then \$Label = Label("26.05", "27.05", "28.05", "29.05", "30.05")
If \$Input = 23 Then \$Label = Label("02.06", "03.06", "04.06", "05.06", "06.06")
If \$Input = 24 Then \$Label = Label("09.06", "10.06", "11.06", "12.06", "13.06")
EndFunc   ;==>LabelCheck```

Which does this:

```Func Label(\$text1, \$text2, \$text3, \$text4, \$text5)
Local \$Div1 = 80, \$Div2 = 145, \$Div3 = 205, \$Div4 = 270, \$Div5 = 335
GUICtrlCreateLabel(\$text1, \$Div1, 5, 40, 15)
GUICtrlSetFont(-1, 12, "", "", "Arial")
GUICtrlCreateLabel(\$text2, \$Div2, 5, 40, 15)
GUICtrlSetFont(-1, 12, "", "", "Arial")
GUICtrlCreateLabel(\$text3, \$Div3, 5, 40, 15)
GUICtrlSetFont(-1, 12, "", "", "Arial")
GUICtrlCreateLabel(\$text4, \$Div4, 5, 40, 15)
GUICtrlSetFont(-1, 12, "", "", "Arial")
GUICtrlCreateLabel(\$text5, \$Div5, 5, 40, 15)
GUICtrlSetFont(-1, 12, "", "", "Arial")
EndFunc   ;==>Label```

But I want a more automated version so I don't need to add the dates in a week manually.

Something like Label(\$Day1, \$Day2, \$Day3, \$Day4, \$Day5)

Or Label(\$Day[0], \$Day[1], \$Day[2], \$Day[3], \$Day[4])

Where the \$Day is based off the weekdate. It could not be from the current date, because it needs to work for any week.

##### Share on other sites

This example converts a year's week number to the days' dates of that week starting on the Monday - the first day of theweek.

```#include <Date.au3>
#include <Array.au3>

Local \$iWeekNum = 1
Local \$Year = 2014

Local \$s = _DateFromWeekNumber(\$Year, \$iWeekNum)
Local \$sDates = _DateFormat(\$s, "dddd MMM.dd.yyyy")
For \$i = 1 To 6
\$sDates &= "|" & _DateFormat(_DateAdd("D", \$i, \$s), "dddd MMM.dd.yyyy")
Next
;ConsoleWrite(\$sDates & @LF)
Local \$aDates = StringSplit(\$sDates, "|", 2)

; The week with the first Thursday of the year is week number 1.
;Returns the date of the Monday of the week number.
Func _DateFromWeekNumber(\$iYear, \$iWeekNum)
Local \$Date, \$sFirstDate = _DateToDayOfWeek(\$iYear, 1, 1)
If \$sFirstDate < 6 Then
\$Date = _DateAdd("D", 2 - \$sFirstDate, \$iYear & "/01/01")
ElseIf \$sFirstDate = 6 Then
\$Date = _DateAdd("D", \$sFirstDate - 3, \$iYear & "/01/01")
ElseIf \$sFirstDate = 7 Then
\$Date = _DateAdd("D", \$sFirstDate - 5, \$iYear & "/01/01")
EndIf
;ConsoleWrite(_DateToDayOfWeek(\$iYear, 1, 1) &"  ")
Local \$aDate = StringSplit(\$Date, "/", 2)
EndFunc   ;==>_DateFromWeekNumber

; Format date
; \$sDate, input date in the format yyyy/MM/dd[ hh:mm:ss]
Func _DateFormat(\$sDate, \$sFormat)
\$hGui = GUICreate("")
\$idDate = GUICtrlCreateDate(\$sDate, 10, 10)
GUICtrlSendMsg(\$idDate, 0x1032, 0, \$sFormat) ; or "dddd, MMMM d, yyyy hh:mm:ss tt"); or "hh:mm tt"
GUIDelete(\$hGui)
Return \$FormatedDate
EndFunc   ;==>_DateFormat```

##### Share on other sites

This example converts a year's week number to the days' dates of that week starting on the Monday - the first day of theweek.

```#include <Date.au3>
#include <Array.au3>

Local \$iWeekNum = 1
Local \$Year = 2014

Local \$s = _DateFromWeekNumber(\$Year, \$iWeekNum)
Local \$sDates = _DateFormat(\$s, "dddd MMM.dd.yyyy")
For \$i = 1 To 6
\$sDates &= "|" & _DateFormat(_DateAdd("D", \$i, \$s), "dddd MMM.dd.yyyy")
Next
;ConsoleWrite(\$sDates & @LF)
Local \$aDates = StringSplit(\$sDates, "|", 2)

; The week with the first Thursday of the year is week number 1.
;Returns the date of the Monday of the week number.
Func _DateFromWeekNumber(\$iYear, \$iWeekNum)
Local \$Date, \$sFirstDate = _DateToDayOfWeek(\$iYear, 1, 1)
If \$sFirstDate < 6 Then
\$Date = _DateAdd("D", 2 - \$sFirstDate, \$iYear & "/01/01")
ElseIf \$sFirstDate = 6 Then
\$Date = _DateAdd("D", \$sFirstDate - 3, \$iYear & "/01/01")
ElseIf \$sFirstDate = 7 Then
\$Date = _DateAdd("D", \$sFirstDate - 5, \$iYear & "/01/01")
EndIf
;ConsoleWrite(_DateToDayOfWeek(\$iYear, 1, 1) &"  ")
Local \$aDate = StringSplit(\$Date, "/", 2)
EndFunc   ;==>_DateFromWeekNumber

; Format date
; \$sDate, input date in the format yyyy/MM/dd[ hh:mm:ss]
Func _DateFormat(\$sDate, \$sFormat)
\$hGui = GUICreate("")
\$idDate = GUICtrlCreateDate(\$sDate, 10, 10)
GUICtrlSendMsg(\$idDate, 0x1032, 0, \$sFormat) ; or "dddd, MMMM d, yyyy hh:mm:ss tt"); or "hh:mm tt"
GUIDelete(\$hGui)
Return \$FormatedDate
EndFunc   ;==>_DateFormat```

Thanks. I was able to change it to my needs and implement it into my other functions.

##### Share on other sites

Would be nice if you shared your modification with us.

```Func LabelCheck(\$Input)
\$LabelDelete = GUICtrlDelete(\$Label1) & GUICtrlDelete(\$Label2) & GUICtrlDelete(\$Label3) & GUICtrlDelete(\$Label4) & GUICtrlDelete(\$Label5)

Local \$Year = @YEAR

Local \$s = _DateFromWeekNumber(\$Year, \$Input)
Local \$sDates = _DateFormat(\$s, "dd.MM")
For \$i = 1 To 6
\$sDates &= "|" & _DateFormat(_DateAdd("D", \$i, \$s), "dd.MM")
Next
;ConsoleWrite(\$sDates & @LF)
Local \$aDates = StringSplit(\$sDates, "|", 2)
EndFunc   ;==>LabelCheck

Func _DateFromWeekNumber(\$iYear, \$iWeekNum)
Local \$Date, \$sFirstDate = _DateToDayOfWeek(\$iYear, 1, 1)
If \$sFirstDate < 6 Then
\$Date = _DateAdd("D", 2 - \$sFirstDate, \$iYear & "/01/01")
ElseIf \$sFirstDate = 6 Then
\$Date = _DateAdd("D", \$sFirstDate - 3, \$iYear & "/01/01")
ElseIf \$sFirstDate = 7 Then
\$Date = _DateAdd("D", \$sFirstDate - 5, \$iYear & "/01/01")
EndIf
;ConsoleWrite(_DateToDayOfWeek(\$iYear, 1, 1) &"  ")
Local \$aDate = StringSplit(\$Date, "/", 2)
EndFunc   ;==>_DateFromWeekNumber

Func _DateFormat(\$sDate, \$sFormat)
\$hGui = GUICreate("")
\$idDate = GUICtrlCreateDate(\$sDate, 10, 10)
GUICtrlSendMsg(\$idDate, 0x1032, 0, \$sFormat) ; or "dddd, MMMM d, yyyy hh:mm:ss tt"); or "hh:mm tt"
GUIDelete(\$hGui)
Return \$FormatedDate
EndFunc   ;==>_DateFormat```

## Create an account

Register a new account

×

• Wiki

• Back

• #### Beta

• Git
• FAQ
• Our Picks
×
• Create New...