Link to home
Start Free TrialLog in
Avatar of tomgribbin
tomgribbin

asked on

problems with win 2000 bat file using %date%

Hi,

I am running windows 2000 Pro. When I access the command prompt and type the command %date%

I am returned the message: 'Fri' is not recognized as an internal or exteral command, operable programme or batch file

I want to use %date% in a .bat file I am creating to create a files on a daily basis named the current date.

'Fri' obviously relates to today which is a Friday but I do not want the day I just want the date in the format 28-11-03 not Fri 28-11-03.

How can I change the system to stop the Fri being generated which is stopping my .bat file from running.

Many thanks,

Tom Gribbin
<Email address removed by SerCouWisMOD pursuant of https://www.experts-exchange.com/help/mistakes.jsp#2 >
Avatar of shivsa
shivsa
Flag of United States of America image

solve this problem by creating a variable named "date" and put the current date into that variable. use this command at the beginning of the batch file:

for /f  "delims==" %%G IN ('date /t') do set date=%%G

now when you'll write %date% (within the batch file you'll recieve the date)
I had a similiar issue.   I use 2 old com files called getmonth.com and getday.com and I create batchfiles that do something like the following:


GETMONTH
IF ERRORLEVEL 1 IF NOT ERRORLEVEL 2 SET MMDD=01
IF ERRORLEVEL 2 IF NOT ERRORLEVEL 3 SET MMDD=02
etc..etc...all the way to 12

then
GETDAY
IF ERRORLEVEL 1 IF NOT ERRORLEVEL 2 SET MMDD=%MMDD%01
IF ERRORLEVEL 2 IF NOT ERRORLEVEL 3 SET MMDD=%MMDD%02
etc...  all the way to 31  

this worked well in NT and 2k.  


or like this
FOR /f "tokens=2-4 delims=/ " %%a in ('date /t') do set date=%%a%%b%%c
If you want your date in different format, you can rearrange the variables a, b and c.
Avatar of tomgribbin
tomgribbin

ASKER

Shivsa,

Thanks for your swift reply. the code for batch file is below. where and how would i inser the variable which you mention? Sorry for being dim - batch file follows:

cd\
copy e:\datamain.xls e:\dailystats\
rename e:\dailystats\datamain.xls e:\dailystats\%date%.xls

Cheers
for /f "tokens=1,2,3,4 delims=/ " %%a in ('date /t') do set today=%%b-%%c-%%d
%today% will have the format u asked for.
ASKER CERTIFIED SOLUTION
Avatar of shivsa
shivsa
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial