Computing.Net > Forums > Windows NT > Batch Script query

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Batch Script query

Reply to Message Icon

Name: rajendra_pai
Date: January 21, 2004 at 03:40:35 Pacific
OS: Windows NT
CPU/Ram: P4, 256 MB RAM
Comment:

HI,

I am trying to write a batch script in MS-DOS that will stop execution when current Time is greater than specified time.

for this we need comparison between strings or dates.

please let me know if any such conversion formats are available in Batch script commands. Your help is appreciated.



Sponsored Link
Ads by Google

Response Number 1
Name: IVO
Date: January 21, 2004 at 08:30:00 Pacific
Reply:

Yes, you can setup a script acting as you posted, but it seems to me to waste CPU power, as batch code is not planned to run in that way.

Anyway you can convert time into integer numbers and then compare them to stop the run. This is done using the /A switch of the Set command that enables arithmetic computing of variables under Windows NT/2K/XP.

If you are still interested, post again specifying better what you want to do and the format of time as set in your system, i.e. am/pm or 24h military (Report the output of the Time /T command).


0

Response Number 2
Name: rajendra_pai
Date: January 21, 2004 at 22:55:54 Pacific
Reply:

HI,

Thanks for the update...

here is my program,,

end time is set to 03:00:00.00(using 24 Hr clk) format.

if current time exceeds end time then perform specific action A, else perform action B.
*****Batch Script Starts here******

@echo off

rem Setting End Time

Set END_TIME = "03:00:00.00";

echo %END_TIME% (does not display end_time)

echo %TIME%

if %TIME% GTR %END_TIME% echo 'Current Time Greater than end Time' (does not work properly since END_TIME var does not contain right value)

*****Batch Script Ends here******

Thanks,
Raj


0

Response Number 3
Name: IVO
Date: January 22, 2004 at 02:26:41 Pacific
Reply:

Below you find a sample script to help you to achieve your job.
--------------------
@Echo Off
:: CKTIME Sample script to test for an expiration time

:: [Prompting for End Time]
Echo.
Set /P QT=Enter End Time as HH:MM:SS ^>
Set EndTime=%QT%
Echo.

:: [Setting End Time]
Set EndTime=%QT%
If "%EndTime:~0,1%"==" " Set EndTime=0%EndTime:~1,7%

:: [Setting System Time]
Set SysTime=%Time:~0,8%
If "%SysTime:~0,1%"==" " Set SysTime=0%SysTime:~1,7%

Echo Set End Time is %EndTime%
Echo Current Time is %SysTime%
Echo.

: [Comparing System Time vs End Time]
If %SysTime% gtr %EndTime% Echo Current Time greater than End Time
If %SysTime% leq %EndTime% Echo Current Time low or equal than End Time

Set EndTime=
Set SysTime=
Set QT=
--------------------
The time separators typed at prompt must be the same used by your system time otherwise the comparison does not work. No check is made to ensure the typed time is correct. I used to prompt for End Time to let you experiment with the script. The time is accounted at seconds, millisecs being disregarded.

By the way, never type blanks between the variables and the = symbols!

I hope this helps, if you need more support, post again.
Good Work


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More


NT 4 still worthwhile? Edit registry in WinNT 4....



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Windows NT Forum Home


Sponsored links

Ads by Google


Results for: Batch Script query

Batch Script to make a directory that has the today's date as a name www.computing.net/answers/windows-nt/batch-script-to-make-a-directory-that-has-the-todays-date-as-a-name/3396.html

batch script to launch a persistent app www.computing.net/answers/windows-nt/batch-script-to-launch-a-persistent-app/11156.html

Starting a batch script automatically www.computing.net/answers/windows-nt/starting-a-batch-script-automatically/17757.html