Time is of the essence 
Author Message
 Time is of the essence

I have a program that is launched by a batch file when certain
criteria are met, but I want to add time as one more variable. I only
want the program to run between the hours of 5:00 P.M. and 9:00 A.M.

So what I need is a snippet of code (Batch file, VBScript, or WSH)
that will set a condition based on the current time. Maybe something
like this:

...

IF NOT (Between the hours of 5 PM and 9 AM) GOTO END

Start MyProgram.exe

END

...

Any help would be greatly appreciated. Thanks.



Sat, 25 Sep 2004 22:25:37 GMT  
 Time is of the essence

Quote:

> I have a program that is launched by a batch file when certain
> criteria are met, but I want to add time as one more variable. I only
> want the program to run between the hours of 5:00 P.M. and 9:00 A.M.

> So what I need is a snippet of code (Batch file, VBScript, or WSH)
> that will set a condition based on the current time.

VBScript hosted by WSH:

' Doesn't care about AM/PM or 24-hour display
MyHour = Left(FormatDateTime(Now, vbShortTime), 2)

' Run program between 5:00 P.M. and 9:00 A.M
If MyHour > 16 Or MyHour < 9 Then
  Set oShell = CreateObject("WScript.Shell")
  Shell.Run "MyProgram.exe", 1, True
End If

--
torgeir



Sat, 25 Sep 2004 22:41:26 GMT  
 Time is of the essence
If (Hour(Now()) > 9) and (Hour(Now()) < 5) Then
    'Put executing code here
End If


Sat, 25 Sep 2004 22:52:44 GMT  
 Time is of the essence
Ooops 5 should be 17

P.


Quote:
> If (Hour(Now()) > 9) and (Hour(Now()) < 5) Then
>     'Put executing code here
> End If



Sat, 25 Sep 2004 23:04:43 GMT  
 Time is of the essence

Quote:

> I have a program that is launched by a batch file when certain
> criteria are met, but I want to add time as one more variable. I only
> want the program to run between the hours of 5:00 P.M. and 9:00 A.M.

> So what I need is a snippet of code (Batch file, VBScript, or WSH)
> that will set a condition based on the current time. Maybe something
> like this:

> ...

> IF NOT (Between the hours of 5 PM and 9 AM) GOTO END

> Start MyProgram.exe

> END

> ...

> Any help would be greatly appreciated. Thanks.


for /f "tokens=5 delims=: " %%a in (
 'echo.^|time^|find "urrent"') do set /a hour = 1%%a - 100
if %hour% LSS 17 goto :EOF
if %hour% GTR 8  goto :EOF

--

u n z i p    m y    a d d r e s s    t o    s e n d    e - m a i l



Sun, 26 Sep 2004 02:35:42 GMT  
 Time is of the essence

Quote:


> for /f "tokens=5 delims=: " %%a in (
>  'echo.^|time^|find "urrent"') do set /a hour = 1%%a - 100
> if %hour% LSS 17 goto :EOF
> if %hour% GTR 8  goto :EOF

Thanks to everyone who responded. Easiest thing for me is to go with
Phil's pure batch solution. Thanks again.


Sun, 26 Sep 2004 07:15:49 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. Time is of the essence

2. Format date/time in DTPicker to display AM/PM or 24 hour time

3. Showing the time where I am

4. Regular expression - It should be easy, but I am having a bad time

5. Time function, displaying AM PM

6. my search-loop problem boiled down to its essence

7. Am I lucky or just playing with time?!

8. Am I running in design-time ?

9. I am trying to update a record, i am not using data control

10. I am learning VB.NET and am wondering....

11. I am trying to update a record, i am not using data control

12. When is 5:00 AM not 5:00 AM? When it's 5:00 AM.

 

 
Powered by phpBB® Forum Software