Jump to content

Recommended Posts

Posted

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!

Posted

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 Gude
How 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

Posted (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 by mmoalem
Posted

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

 

  • 6 years later...
Posted (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 by lbsl

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
×
×
  • Create New...