Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
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.

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).

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

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 TimeSet 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

![]() |
NT 4 still worthwhile?
|
Edit registry in WinNT 4....
|

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