mmoalem Posted May 5, 2016 Posted May 5, 2016 Hi there all - how can I find out if $now is between 2pm to 2am and if so run a function - any help will be most welcomed!
BrewManNH Posted May 5, 2016 Posted May 5, 2016 What have you tried, what have you searched for? This question gets asked about once a month, search the forum for any number of answers. 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
mmoalem Posted May 6, 2016 Author Posted May 6, 2016 (edited) 23 hours ago, BrewManNH said: What have you tried, what have you searched for? This question gets asked about once a month, search the forum for any number of answers. Hi and thanks - sorry but been sreaching for the solution here and on google - i search for 'exectute function between specific times' for run command between sepecific times' for 'autoit between given times' etc etc - cant find anything I could make work for me... I an very new to coding and probably the answer was there somewhere but am not sure how to read these answers and understand the code... I know NowTime will give me the the time and this is what I can make of it but doesnt work If _NowTime (4) > 14:00 And < 02:00 Then ... Edited May 6, 2016 by mmoalem
mmoalem Posted May 6, 2016 Author Posted May 6, 2016 OK figured a solution out but is that the most efficient way of achieving this ??? #include <Date.au3> $TimeMarker=@HOUR-2 If $TimeMarker<0 Then $TimeMarker=$TimeMarker+24 If $TimeMarker>=12 And $TimeMarker<24 Then _FunctionToBeExecuted
mikell Posted May 7, 2016 Posted May 7, 2016 On 5/5/2016 at 0:08 AM, mmoalem said: $now is between 2pm to 2am Couldn't you simply use If @HOUR < 2 or @HOUR > 13 Then ...
mmoalem Posted May 7, 2016 Author Posted May 7, 2016 2 hours ago, mikell said: Couldn't you simply use If @HOUR < 2 or @HOUR > 13 Then ... yeah that definitely makes more sense thanks
lbsl Posted September 1, 2022 Posted September 1, 2022 (edited) #include <Math.au3> Local $TimeStart = Number(StringReplace("22:00", ":", "")) Local $TimeEnd = Number(StringReplace("07:00", ":", "")) Local $TimeCurrent = @HOUR & @MIN Local $PerformAction = False Local $LowestTime = _Min($TimeStart, $TimeEnd) Local $HighestTime = _Max($TimeStart, $TimeEnd) If $TimeEnd < $TimeStart Then ;If the time-window falls over night ConsoleWrite("Is " & $TimeCurrent & "<" & $LowestTime & " Or " & $TimeCurrent & ">=" & $HighestTime & "?" & @CRLF) If $TimeCurrent < $LowestTime Or $TimeCurrent >= $HighestTime Then $PerformAction = True EndIf Else ; If the time-window falls within the same day ConsoleWrite("Is " & $TimeCurrent & "<" & $HighestTime & " And " & $TimeCurrent & ">=" & $LowestTime & "?" & @CRLF) If $TimeCurrent < $HighestTime And $TimeCurrent >= $LowestTime Then $PerformAction = True EndIf EndIf If $PerformAction Then ConsoleWrite("inside time-scope to perform action" & @CRLF) ;perform action Else ConsoleWrite("Outside time-scope to perform action" & @CRLF) EndIf It could perhaps be optimized differently, but this way you have covered a time-frame on either the same day or one spanning across two days. The literals in the stringreplace section on top were officially variables in my operational version that were filled from an ini-file parameter. Edited September 1, 2022 by lbsl
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