SDG Posted January 29, 2014 Posted January 29, 2014 (edited) Hello all, I am new with Autoit, I'm curious if there is a way to read the output of the calendar for a date in the past or the future and add days, weeks, month or/and years to the chosen calender date? similar to this webpage http://www.timeanddate.com/date/dateadded.html?d1=15&m1=4&y1=2014&type=add&ay=&am=&aw=3&ad= for now I just need to add 5 days to a chosen Date I have this small script $Date1 = GUICtrlCreateDate("2014/01/29 20:46:39", 60, 10, 200, 25) $Calculate = GUICtrlCreateButton("Calculate", 120, 60, 75, 25) $Label = GUICtrlCreateLabel("Three weeks from entered date", 16, 100, 150, 20) $Input1 = GUICtrlCreateInput("", 180, 100, 130, 21) GUICtrlSetState(-1, $GUI_DISABLE) GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Calculate $InputDate = Int(GUICtrlRead($Date1)) $sNewDate = _DateAdd( 'd',5, _NowCalcDate()) $myCalc = Stringreplace ( $sNewDate , "/", "-") GUICtrlSetData($Input1, string($myCalc)) EndSwitch WEnd Many thanks in advance Edited January 29, 2014 by SDG
BrewManNH Posted January 29, 2014 Posted January 29, 2014 You're reading from the Date control and putting it into $InputDate, but you're using _NowCalcDate in your _DateAdd, probably not what you wanted to do is it? If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator
SDG Posted January 29, 2014 Author Posted January 29, 2014 (edited) You're reading from the Date control and putting it into $InputDate, but you're using _NowCalcDate in your _DateAdd, probably not what you wanted to do is it? Hi BrewManNH, No, that is just to make the script running, what I've done will add 5 days to Today's Date. And what I'm looking for, is to choose a date from the calender like " 5th Feb 2014"and add 5 days to it Feel free to rewrite the code as you wish to come close to the desired result Edited January 29, 2014 by SDG
SDG Posted January 30, 2014 Author Posted January 30, 2014 so far I've it with help of Google like this #include <GuiDateTimePicker.au3> #include <Date.au3> #include <ButtonConstants.au3> $hGui = GUICreate("Date calculator: Add to or subtract from a date", 336, 130, 100, 100) $hdate = GUICtrlCreateDate(_Now(), 45,20, 250, 20, 0x00) $hWndDate = ControlGetHandle($hGui, "", $hdate) _GUICtrlDTP_SetFormat($hWndDate, "yyyy.MM.dd dddd") GUISetState() $Calculate = GUICtrlCreateButton("Calculate", 120, 60, 75, 25) $Label = GUICtrlCreateLabel("Three weeks from entered date", 16, 100, 150, 20) $Input1 = GUICtrlCreateInput("", 180, 100, 130, 21) GUISetState(@SW_SHOW) While 1 $msg = GUIGetMsg() Switch $msg Case -3 Exit Case $Calculate $myCalc = GUICtrlRead($hdate) GUICtrlSetData($Input1, string($myCalc)) ; I want to add 5 days to the output meaning $mycalc_value plus 5 days EndSwitch WEnd now, how can I add fixed days to the outcome? If I choose the 5th Jan 2014 on the calender I want the output to be the 10th Jan 2014. Many thanks in advance
Geir1983 Posted January 30, 2014 Posted January 30, 2014 #include <GuiDateTimePicker.au3> #include <Date.au3> #include <ButtonConstants.au3> $hGui = GUICreate("Date calculator: Add to or subtract from a date", 336, 130, 100, 100) $hdate = GUICtrlCreateDate(_Now(), 45,20, 250, 20, 0x00) $hWndDate = ControlGetHandle($hGui, "", $hdate) _GUICtrlDTP_SetFormat($hWndDate, "yyyy/MM/dd") GUISetState() $Calculate = GUICtrlCreateButton("Calculate", 120, 60, 75, 25) $Label = GUICtrlCreateLabel("Three weeks from entered date", 16, 100, 150, 20) $Input1 = GUICtrlCreateInput("", 180, 100, 130, 21) GUISetState(@SW_SHOW) While 1 $msg = GUIGetMsg() Switch $msg Case -3 Exit Case $Calculate $myCalc = GUICtrlRead($hdate) GUICtrlSetData($Input1, _DateAdd("D", 5, $myCalc)) ; I want to add 5 days to the output meaning $mycalc_value plus 5 days EndSwitch WEnd
Solution SDG Posted January 30, 2014 Author Solution Posted January 30, 2014 #include <GuiDateTimePicker.au3> #include <Date.au3> #include <ButtonConstants.au3> $hGui = GUICreate("Date calculator: Add to or subtract from a date", 336, 130, 100, 100) $hdate = GUICtrlCreateDate(_Now(), 45,20, 250, 20, 0x00) $hWndDate = ControlGetHandle($hGui, "", $hdate) _GUICtrlDTP_SetFormat($hWndDate, "yyyy/MM/dd") GUISetState() $Calculate = GUICtrlCreateButton("Calculate", 120, 60, 75, 25) $Label = GUICtrlCreateLabel("Three weeks from entered date", 16, 100, 150, 20) $Input1 = GUICtrlCreateInput("", 180, 100, 130, 21) GUISetState(@SW_SHOW) While 1 $msg = GUIGetMsg() Switch $msg Case -3 Exit Case $Calculate $myCalc = GUICtrlRead($hdate) GUICtrlSetData($Input1, _DateAdd("D", 5, $myCalc)) ; I want to add 5 days to the output meaning $mycalc_value plus 5 days EndSwitch WEnd Many thanks Geir1983, your code is working fine. It worked I worked on something similar #include <GuiDateTimePicker.au3> #include <Date.au3> #include <ButtonConstants.au3> $hGui = GUICreate("Date calculator: Add to or subtract from a date", 336, 130, 100, 100) $hdate = GUICtrlCreateDate(_Now(), 45,20, 250, 20, 0x00) $hWndDate = ControlGetHandle($hGui, "", $hdate) _GUICtrlDTP_SetFormat($hWndDate, "yyyy-MM-dd") GUISetState() $Calculate = GUICtrlCreateButton("Calculate", 120, 60, 75, 25) $Label = GUICtrlCreateLabel("Three weeks from entered date", 16, 100, 150, 20) $Input1 = GUICtrlCreateInput("", 180, 100, 130, 21) GUISetState(@SW_SHOW) While 1 $msg = GUIGetMsg() Switch $msg Case -3 Exit Case $Calculate $sNewDate = _DateAdd("w", 3, GUICtrlRead($hdate)) $myCalc = Stringreplace ( $sNewDate , "/", "-") GUICtrlSetData($Input1, string($myCalc)) EndSwitch WEnd
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