Sign in to follow this  
Followers 0
Rosamrin

how to check systemtime?

9 posts in this topic

Hi, Im sorry 4 my noobish question, but indeed Im one ^^

I wrtoe a quite simple script, its more about some clicks on the screen, nothing complicated...

I made a woking loop, but now i want smomething like that:

(By Systemtime I mean the real time e.g. 15:34)

If "systemtime" > 0600 AND < 2359 then "do script" in other words: the loop should be paused between time x and y ...

i found some commands but dont worked... : _Date_Time_GetSystemTime ...

I think there are just some lines to write...

THX a lot!

Share this post


Link to post
Share on other sites



Look in the help file for Macro commands, namely, @hour, @min etc. That might help you in what you're looking for.


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

Share this post


Link to post
Share on other sites

Look in the help file for Macro commands, namely, @hour, @min etc. That might help you in what you're looking for.

THX i found them as well, but i dont know how to use them ... :-(

Share this post


Link to post
Share on other sites

Give some details of what you want to do...


AutoIt 3.3.14.2 X86 - SciTE 3.6.0WIN 8.1 X64 - Other Example Scripts

Share this post


Link to post
Share on other sites

....

If "systemtime" > 0600 AND < 2359 then "do script" in other words: the loop should be paused between time x and y ...

....

Maybe something like this.

#include <Date.au3>

HotKeySet("{ESC}", "Terminate") ; Press Esc button to exit.

Local $sStartTime = "11:42" ; "06:00"
Local $sEndTime = "11:43" ; "23:59"

While 1
    ; Other commands in loop
    ConsoleWrite("Main loop running Time = " & _NowCalc() & @CRLF) ; For demo purposes only.

    Sleep(1000)
    _PauseWithinTimes($sStartTime, $sEndTime)
WEnd


; Pauses script execution while system's time is between "$sStart" time and "$sEnd" time.
Func _PauseWithinTimes($sStart, $sEnd)
    Local $sNow = _NowCalc()
    $sStart = _NowCalcDate() & " " & $sStart
    $sEnd = _NowCalcDate() & " " & $sEnd
    While _DateDiff("n", $sNow, $sStart) < 0 And _DateDiff("n", $sNow, $sEnd) >= 0
        $sNow = _NowCalc()
        Sleep(1000)
        ConsoleWrite("Current Time = " & _NowCalc() & @CRLF) ; For demo purposes only.
    WEnd
    Return
EndFunc   ;==>_PauseWithinTimes

Func Terminate()
    Exit 0
EndFunc   ;==>Terminate

Share this post


Link to post
Share on other sites

Local $sStartTime = "06:00"
Local $sEndTime = "23:59"

While 1
    If _Time_InRange($sStartTime, $sEndTime) Then
        ;;  The time is between 06:00 and 23:59 so do something here using the rest of your code
    Else
        ;; The time is not in the correct range
        ContinueLoop
    EndIf
WEnd


;===============================================================================
; Function Name:   _Time_InRange()
; Description:     Determine if the current time is within a given Range
; Syntax:          _Time_InRange("Low time", "High time")
; Parameter(s):    $sTime - Low end of the range (Start time)
;                  $eTime - High end of the range (End time)
; Requirement(s):   
; Return Value(s): 1 if current time is within the range otherwise 0
; Author(s):   George (GEOSoft) Gedye
; Modification(s): Replaced _NowTime(4) With Formatted @Hour & @Min
; Note(s):    This only uses Hours and Minutes
; Example(s):   MsgBox(0, "Time is good", _Time_InRange("08:00", "23:59"))
;===============================================================================

Func _Time_InRange($sTime, $eTime)
  Local $vRange = 0, $cTime
  $cTime = Number(@Hour & @Min)
  If $cTime >= Number(StringFormat("%04d",StringRegExpReplace($sTime, "\D", ""))) AND _
      $cTime <= Number(StringFormat("%04d",StringRegExpReplace($eTime, "\D", ""))) Then $vRange = 1
  Return $vRange
EndFunc   ;<==> _Time_InRange()


George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites

GeoSoft

Two things I prefer in your example are :-

1/ include files are not necessary; and,

2/ Your function, _Time_InRange(), will accept numeric parameters. That is, will accept 600 or "06:00" 0r "0600" - nicely flexible.

What I do not prefer is the equal sign in

$cTime <= Number(StringFormat("%04d",StringRegExpReplace($eTime, "\D", ""))) Then

This causes the end time to occur a minute later than specified. The end time remains equal to the system's time for a minute until they are not equal. The easy fix being remove that one only equal character.

The "StringFormat()" functions are not necessary.

Malkey

Share this post


Link to post
Share on other sites

Right you are. The = sign should be removed, secondly that is a compatible match to a _Date_InRange() function I did. I did them both for someone that needed them to load at startup, check if the date and time were with in a given range and if so run an application. The whole package did require StringFormat() but I should have removed it later when I split up the functions. The post above was just a c/p from my time.au3 UDF

Thanks.


George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites

THX guys!

I will try as soon as I have some time...

And give some feedback and may be some other litle question...

so far Im happy with ur support!

again THX u!

greetz

Share this post


Link to post
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
Sign in to follow this  
Followers 0