Jump to content
Sign in to follow this  
Guest Jc77

Operators using TIME help

Recommended Posts

Guest Jc77

Hi All.

I want to compare the time against an variable I have.

For example, I have a variable that stores the time.

Now I want to see if the current time is greater than my variable.

Like this...

if _NowTime() < '10:00:00 PM' then

msgbox (0,'','It is not 10 PM yet!')

endif

Really it looks like this since my variable holds the value as HH:MM:SS AM/PM (i.e. 10:00:00 PM) :

if _NowTime() < $MyTime then

msgbox (0,'','The current time is before 10 pm')

endif

But this doesn't seem to work.

How do I convert my variable to use a type of time or how can I use an operator like this

to get what I want?

_NowTime() returns the time in the HH:MM:SS AM/PM format so I was hoping autoit3 could do this

operation.

But it doesn't seem to work.... Any help is appreaciated....

Share this post


Link to post
Share on other sites

Hi All.

I want to compare the time against an variable I have.

For example, I have a variable that stores the time.

Now I want to see if the current time is greater than my variable.

Like this...

if _NowTime() < '10:00:00 PM' then

msgbox (0,'','It is not 10 PM yet!')

endif

Really it looks like this since my variable holds the value as HH:MM:SS AM/PM (i.e. 10:00:00 PM) :

if _NowTime() < $MyTime then

msgbox (0,'','The current time is before 10 pm')

endif

But this doesn't seem to work.

How do I convert my variable to use a type of time or how can I use an operator like this

to get what I want?

_NowTime() returns the time in the HH:MM:SS AM/PM format so I was hoping autoit3 could do this

operation.

But it doesn't seem to work.... Any help is appreaciated....

AutoIt3 treats dates and times as strings so doing a direct comparison of 2 times like that won't work. Best bet is to use the 24 hour clock (get rid of am/pm) and strip the non-numeric characters out, then it will work.

Other option (as mentioned by MSLx Fanboy) is to use the _DateDiff function with the "s" option for seconds, but again you need to use the 24 hour clock and not AM/PM.

Edited by seanhart

Share this post


Link to post
Share on other sites

Here is a clock script with an alarm function that I borrowed from somewhere. I am sure it could be modified to do what you require.

#include <GuiConstants.au3>
Global $sec = @SEC, $minute, $hour, $light, $time, $clocklabel
opt("WinWaitDelay", 100)
opt("WinTitleMatchMode", 4)
opt("WinDetectHiddenText", 1)
opt("MouseCoordMode", 0)
GUICreate("Max's Clock", 200, 50, (@DesktopWidth - 188) / 2, (@DesktopHeight - 59) / 2)
$clocklabel = GUICtrlCreateLabel("Loading...", 5, 5, 190, 40, 0x1000)
GUICtrlSetFont($clocklabel, 24)
GUISetState()
While 1
    $msg = GUIGetMsg()
    If $msg = -3 Then
        ExitLoop
    ElseIf $sec <> @SEC Then
        GUICtrlSetData($clocklabel, TimeSet())
        AlarmCheck(TimeSet())
    EndIf
WEnd
Exit
Func AlarmCheck($time)
If $time = "6:10:00 PM"Then
MsgBox(0,"","Alarm Message");Alarm function(configure how wanted)
EndIf
EndFunc ;==>AlarmCheck
Func TimeSet()
    $light = " AM"
    $hour = @HOUR
    $minute = @MIN
    $sec = @SEC
    If $hour = 0 Then
        $hour = 12
    ElseIf $hour = 12 Then
        $light = " PM"
    ElseIf $hour > 12 Then
        $hour = (@HOUR) - 12
        $light = " PM"
    EndIf
    $time = $hour & ":" & $minute & ":" & $sec & $light
    Return $time
EndFunc ;==>TimeSet

If anyone recognises it as their script let me know and I will give them the credit deserved.



Time you enjoyed wasting is not wasted time ......T.S. Elliot
Suspense is worse than disappointment................Robert Burns
God help the man who won't help himself, because no-one else will...........My Grandmother

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  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...