Tech Support > Operating Systems > Windows NT > %date% in NT batch files?
%date% in NT batch files?
Posted by Lars Rasmussen on July 30th, 2003


Hi

I have made some small batch jobs (like the one below) on a w2k machine.
They work ok here.
Then i moved the files to a NT server, and then it looks like the NT server
doesn't like %date% and %time% at all.
Is that true?

Other comments to the job are of cource welcome :-)

br Lars

set end_time=22:00

set start_date=%date:~0,2%

rem --------------------------------
if %time:~0,5% GTR %end_time% goto end
if %date:~0,2% NEQ %start_date% goto end
call Specs.bat


Posted by Phil Robyn on July 30th, 2003


Lars Rasmussen wrote:
Yes, %date% and %time% are not recognized by NT4.0's CMD.EXE, but CMD.EXE from
Win2000 should run fine on NT4.0; just replace the NT4.0 CMD.EXE with the one
from a Win2000 machine.

Or, instead of %date% and %time% you could use the following (will also work
in Win2000 or WinXP)

for /f "tokens=5-6 delims=:. " %%a in (
'echo/^|time^|findstr "urrent"'
) do set hh:mm=%%a:%%b
if "%hh:mm:~2,1%" EQU ":" set hh:mm=0%hh:mm%


Assuming that 'date /t' yields 'Wed 07/30/2003' (your settings may vary):

for /f "tokens=1-4 delims=/ " %%a in (
'date /t'
) do set day=%%a&set mm=%%b&set dd=%%c&set yyyy=%%d


OR

for /f "tokens=*" %%a in ('date /t') do set date=%%a


--
Phil Robyn
Univ. of California, Berkeley

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


Posted by Lars Rasmussen on July 30th, 2003


Hi

Thanks. Works great :-)

br Lars

"Phil Robyn" <zipprobyn@uclink.berkeley.edu> wrote in message
news:u4Ef1fnVDHA.1928@TK2MSFTNGP12.phx.gbl...



Similar Posts