Jump to content

Changing date-time restriction?


Recommended Posts

I need to add a new "variable" (have a got the right term?) to this script portion that determines whether or not a script will run:

#include <Date.au3>
$StartTime = "06:00"     ;  adjust START time here in 24-hour time
$EndTime = "23:59"     ;  adjust END time here in 24-hour time
$CurrentTime = _NowTime(4)

If @MON = 12 and @MDay >=1 and @MDay <=25 Then     ; Advent event will run from December 1st to the 25th!
If $CurrentTime >= $StartTime AND $CurrentTime <= $EndTime Then
;It's not a valid time for script to run so exit without running
    Exit
EndIf
EndIf
; ========== My script down below: ===========================================================

I found @MON and @MDay in the help file. I hope that I'm more or less on the right track with this. What's needed here is to limit this script to work only under these conditions:

1. Between 06:00 a.m. and 11:59 p.m.,

2. From December 1st to the 25th.

(That way I can just set this to run daily in my scheduler and avoid hassles. My scheduler is good, but it just can't limit tasks in this way. So AI will be what actually controls when this script does run, namely, Dec.01-25 each year.)

I know I screwed up somewhere (and it's me copying code from another script in the forum so I might be completely off with the "If" statement re days the month of December, but hopefully it's easy enough to fix.

Thank you! :)

Edited by Diana (Cda)
Link to comment
Share on other sites

Maybe this one will be right:

#include <Date.au3>
 
 $StartTime = "06:00"     ;  adjust START time here in 24-hour time
 $EndTime = "23:59"     ;  adjust END time here in 24-hour time
 $CurrentTime = _NowTime(4)
 
 If @MON <> 12 Or @MDay > 25 Then     ; Advent event will run from December 1st to the 25th!
     If $CurrentTime < $StartTime Or $CurrentTime > $EndTime Then
     ;It's not a valid time for script to run so exit without running
         Exit
     EndIf
 EndIf
 ; ========== My script down below: ===========================================================
Link to comment
Share on other sites

  • Developers

Try this version to see if that covers them all:

#include <Date.au3>
$StartTime = "06:00";  adjust START time here in 24-hour time
$EndTime = "23:59";  adjust END time here in 24-hour time
$CurrentTime = _NowCalc()
$CurrentDate = _NowCalcDate()
If (@MON < 12) Or (@MON = 12 And @MDAY <= 25) Then; Advent event will run from December 1st to the 25th!
    If _DateDiff("s", _NowCalcDate() & " " & $StartTime, $CurrentTime) >= 0 And _DateDiff("s", _NowCalcDate() & " " & $EndTime, $CurrentTime) <= 0 Then
        ConsoleWrite("### run ####" & @CRLF) 
    ;It's not a valid time for script to run so exit without running
        Exit
    EndIf
EndIf
; ========== My script down below: ===========================================================

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

Maybe this one will be right:

#include <Date.au3>
 
 $StartTime = "06:00"     ;  adjust START time here in 24-hour time
 $EndTime = "23:59"     ;  adjust END time here in 24-hour time
 $CurrentTime = _NowTime(4)
 
 If @MON <> 12 Or @MDay > 25 Then     ; Advent event will run from December 1st to the 25th!
     If $CurrentTime < $StartTime Or $CurrentTime > $EndTime Then
     ;It's not a valid time for script to run so exit without running
         Exit
     EndIf
 EndIf
 ; ========== My script down below: ===========================================================oÝ÷ Ûú®¢×­æ¥)bëaË(ëb¢v¬!Ƨºw^®ËZØ­jwb·lm¢Ú­úèZ´²H§v ÷§mçè­äázËk¹Ën­æ§v̧µ¬ajÊÞ¨§yÖÚ²'­ëäájÝý±©pk+¦[¬~æx]Ù÷öÜ(®J''â®ËmzËa£¯z²-ßÛººÞÙr×ÈvæÊr§çmç§vئz)íë®*m¶|ÓKhµë-¶­g«b²Ë©¦vÚ!j^+-ë®*mÂ¥vz-v§ÊØbÞq«¬zØ^rêëz{mg¢²z-}©ex.׫¶¢wb¶*'²íë®*m!©l¢Æ°mçè­ëaËajÛaz·¢±ª®¢Ø-Û®¢Ü!z{azÇ+l¥v»§mëpyéíílµ©ÝÛa¶«yú+y§-¹©eÊ«¨¶[v櫨µ*©àx-«ly鬶âÅçmæ¢÷°'!©±¦ì¢[­z§¢Ç§±ëh䨶Þ׫jצëjºe¶«¨¶)ìµæ¡ú®¢Ø-ªê-jëh×6If @MON <> 12 Or @MDay < 25 Then     ; Advent event will run from December 1st to the 25th!

I'll keep testing this, however, as I'm not sure this is okay yet. The next test will involve changing the system date to something no in December to see what happens then.

I have a question, though. Something that would not have occurred to me to do. Why do you use an "Or" in the If line? For me, what comes logically to mind is "and". The condition is that the script will run _if_ it is December _AND_ as long as the date is between 1 and 25. So both conditions apply and not an either/or ... (?) So is "Or" actually correct here? Just curious. It seems to be opposite to logic (but, then, what the heck do I know ... ??!!!! <lol>).

Thanks! :)

Link to comment
Share on other sites

Try this version to see if that covers them all:

#include <Date.au3>
$StartTime = "06:00";  adjust START time here in 24-hour time
$EndTime = "23:59";  adjust END time here in 24-hour time
$CurrentTime = _NowCalc()
$CurrentDate = _NowCalcDate()
If (@MON < 12) Or (@MON = 12 And @MDAY <= 25) Then; Advent event will run from December 1st to the 25th!
    If _DateDiff("s", _NowCalcDate() & " " & $StartTime, $CurrentTime) >= 0 And _DateDiff("s", _NowCalcDate() & " " & $EndTime, $CurrentTime) <= 0 Then
        ConsoleWrite("### run ####" & @CRLF) 
;It's not a valid time for script to run so exit without running
        Exit
    EndIf
EndIf
; ========== My script down below: ===========================================================

Jos

Thank you. I will try this one, too.
Link to comment
Share on other sites

I'll keep testing this, however, as I'm not sure this is okay yet. The next test will involve changing the system date to something no in December to see what happens then.Nope. Something's definitely off. Changed the date to December 26, 2007 and neither

If @MON <> 12 Or @MDay > 25 Then

nor

If @MON = 12 And @MDay < 25 Then

and any number of variations that I could think of made this work.

The message box script kept popping up no matter if it was after December 25th this year or even into random dates next year. <sigh>

Well, I'll put this one to rest for now. Since it's Xmas tomorrow, lots to do. Just would be nice to have gotten this to work as we're still in the countdown to Xmas ... <g>

Thanks! Much appreciated. :)

Link to comment
Share on other sites

I have a question, though. Something that would not have occurred to me to do. Why do you use an "Or" in the If line? For me, what comes logically to mind is "and". The condition is that the script will run _if_ it is December _AND_ as long as the date is between 1 and 25. So both conditions apply and not an either/or ... (?) So is "Or" actually correct here? Just curious. It seems to be opposite to logic (but, then, what the heck do I know ... ??!!!! <lol>).

Thanks! :)

If @MON <> 12 Or @MDay > 25 Then Exit

First of all: AutoIt evaluates from left to right.

- if month is other then 12 then no matter of the day Exit is executed

- if month is 12 then execution of Exit depends on Day

Edited by Zedna
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...