Jump to content

date input and manipulation


Go to solution Solved by goodmanjl531,

Recommended Posts

I am trying to create a calendar generator

I use a date control GUI to pick start date.

I then need to add 6 days to get the last day of the week picked.  Then i want to add a week to each to move week by week( I am assuming original date will be a sunday)

part of my code...

the msgbox with the $currentFYweekDTEnd   shows a 0  then when i add the 2 dates at the end i get errors. so the _dateadd is not working right.

 

Thanks in Advance for any and all help

 

#include <date.au3>
#include <ButtonConstants.au3>
#include <DateTimeConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>

$Form1_1 = GUICreate("Fiscal Year Builder", 385, 487, 285, 125)
$Input_Fiscal_Year = GUICtrlCreateInput("YYYY", 191, 16, 78, 21)
$Label1 = GUICtrlCreateLabel("Fiscal Year", 39, 16, 53, 17)
$Group1 = GUICtrlCreateGroup("Weeks per QTR", 191, 224, 110, 97)
$Radio1 = GUICtrlCreateRadio("4-5-4", 215, 248, 81, 25)
GUICtrlSetState(-1, $GUI_CHECKED)
$Radio2 = GUICtrlCreateRadio("4-5-5", 215, 288, 89, 25)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group2 = GUICtrlCreateGroup("Weeks in Year", 23, 224, 110, 97)
$Radio3 = GUICtrlCreateRadio("52", 39, 248, 65, 33)
GUICtrlSetState(-1, $GUI_CHECKED)
$Radio4 = GUICtrlCreateRadio("53", 39, 288, 65, 25)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Date_FS = GUICtrlCreateDate("2022/01/01", 23, 96, 134, 105)
$Button1 = GUICtrlCreateButton("Generate", 95, 344, 166, 81)
$DATE_FE = GUICtrlCreateDate("2022/01/01", 191, 99, 134, 105)
$Label2 = GUICtrlCreateLabel("Fiscal Start Date", 39, 56, 79, 17)
$Label3 = GUICtrlCreateLabel("Fiscal End Date", 191, 56, 76, 17)
GUISetState(@SW_SHOW)


While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            createcalendar()
    EndSwitch
    wend
Exit

func createcalendar()

$Fiscal_Year=GUICtrlRead($Input_Fiscal_Year)
            $weeks454=GUICtrlread($Radio1)
            $weeks455=GUICtrlRead($Radio2)
            $52weeks=GUICtrlRead($Radio3)
            $53weeks=GUICtrlRead($Radio4)
            $FYStart = GUICtrlRead($Date_FS)
            $FYEnd = GUICtrlRead($DATE_FE)
            If $weeks454 =1 then
                $weeks1=4
                $weeks2=5
                $weeks3=4
            Else
                $weeks1=4
                $weeks2=5
                $weeks3=5
            EndIf

            If $52weeks = 1 Then
                $TotalWeeks=52
            Else
                $TotalWeeks=53
            EndIf

;MAIn Counters
$current_month=1
$current_Qtr=1
$current_week=1
$monthsInQtr=1
$CurrentWeekInMonth=1
$currentFYWeekDate=$FYStart
$currentFYweekDTEnd=_DateAdd('d',6,$currentFYWeekDate)
MsgBox(0,""," S Date:"& $currentFYWeekDate &@CRLF &"E DATE:"&$currentFYweekDTEnd)


While $current_week <= $TotalWeeks
    Select
        Case $current_month = 1 or 4 or 7 or 10
            $TotalWeekInMonth = $weeks1
        Case $current_month = 2 or 5 or 8 or 11
            $TotalWeekInMonth = $weeks2
        Case $current_month = 3 or 6 or 9 or 12
            $TotalWeekInMonth = $weeks3
    EndSelect

    MsgBox(0,"","FY:" & $Fiscal_Year & @CRLF &"QTR:" & $current_Qtr & @CRLF & "Month:"  & $current_month & @CRLF & "Week:" & $current_week & @CRLF & "Start date:"  &$currentFYWeekDate & @CRLF & "End date: " & $currentFYweekDTEnd)

    $current_week = $current_week + 1
    $CurrentWeekInMonth = $CurrentWeekInMonth+1
    $currentFYWeekDate = _DateAdd('w',1,$currentFYWeekDate)
    $currentFYweekDTEnd= _DateAdd('w',1,$currentFYweekDTEnd)

    If $CurrentWeekInMonth > $TotalWeekInMonth Then
        $CurrentWeekInMonth=1
        $current_month =$current_month +1
        $monthsInQtr =$monthsInQtr + 1
    EndIf
    If $monthsInQtr = 4 Then
        $current_Qtr =$current_Qtr +1
        $monthsInQtr = 1
    EndIf

WEnd
EndFunc

 

Link to comment
Share on other sites

  • Developers

Are you sure the format of the Date is valid as defined in the helpfile? Show us the exact Date used for input. 

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

Link to comment
Share on other sites

30 minutes ago, goodmanjl531 said:

i get error code 3 invalid date which is odd

Not so odd.  You have to understand that date is not a variable type in AutoIt.  All variables are variant and dates are consider as string.  So there is multiple ways to save date field in a variable.  You need to make sure your string follow the rule of the functions you rely on.

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...