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. Regular expression - It should be easy, but I am having a bad time

3. Showing the time where I am

4. Time function, displaying AM PM

5. Times Greek boldface/italic and Times vs Symbol

6. Start Time must be before End Time

7. Time & Time Zones

8. ASP Time vs. VB Client time

9. Formatting Time to GMT when current Time Zone not known

10. Object Time Out vs. Session Time Out

11. time zones and daylight saving time

12. Real time From Time Zone information

 

 
Powered by phpBB® Forum Software