EpicKnarvik97 Posted April 29, 2014 Share Posted April 29, 2014 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. Link to comment Share on other sites More sharing options...
Solution Malkey Posted April 30, 2014 Solution Share Posted April 30, 2014 This example converts a year's week number to the days' dates of that week starting on the Monday - the first day of theweek. expandcollapse popup#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) _ArrayDisplay($aDates) ; 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) Return _DateAdd("w", $iWeekNum - 1, $aDate[0] & "/" & $aDate[1] & "/" & $aDate[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" $FormatedDate = GUICtrlRead($idDate) GUIDelete($hGui) Return $FormatedDate EndFunc ;==>_DateFormat Link to comment Share on other sites More sharing options...
EpicKnarvik97 Posted April 30, 2014 Author Share Posted April 30, 2014 This example converts a year's week number to the days' dates of that week starting on the Monday - the first day of theweek. expandcollapse popup#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) _ArrayDisplay($aDates) ; 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) Return _DateAdd("w", $iWeekNum - 1, $aDate[0] & "/" & $aDate[1] & "/" & $aDate[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" $FormatedDate = GUICtrlRead($idDate) GUIDelete($hGui) Return $FormatedDate EndFunc ;==>_DateFormat Thanks. I was able to change it to my needs and implement it into my other functions. Link to comment Share on other sites More sharing options...
guinness Posted April 30, 2014 Share Posted April 30, 2014 Would be nice if you shared your modification with us. UDF List: _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018 Link to comment Share on other sites More sharing options...
EpicKnarvik97 Posted May 1, 2014 Author Share Posted May 1, 2014 Would be nice if you shared your modification with us. expandcollapse popupFunc 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) $Label = Label($aDates[0], $aDates[1], $aDates[2], $aDates[3], $aDates[4]) 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) Return _DateAdd("w", $iWeekNum - 1, $aDate[0] & "/" & $aDate[1] & "/" & $aDate[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" $FormatedDate = GUICtrlRead($idDate) GUIDelete($hGui) Return $FormatedDate EndFunc ;==>_DateFormat 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