date/t not providing day week in server 2003

September 7, 2010 at 03:50:44
Specs: Windows Server 2003
I was able to run a batch file which utilised the day of the week to store an archive file when we were using Windows 2000 Server, but as we have now migrated to Windows 2003 server, the command I used no longer works.
In Windows 2000 Server, date/t used to return "Tue 09/07/2010" and I then used to use:
set day=%date:~0,3%
which returned the first 3 characters of date into my day variable, (ie "tues") but now with Windows 2003 Server date/t returns "09/07/2010" , so I can not get the day of the week!
Does any one have any ideas how to easily get the day into my %day% variable?? It is embedded in an existing batch script which I am not able to modify extensively
Thanks in anticipation,

See More: date/t not providing day week in server 2003

Report •

September 7, 2010 at 15:48:38
It seems to be a problem for others using Win 2003 Server with which I am not familiar. Found this and offer the following 3-liner as a possible work-around. Hope it helps (tested on Win XP Pro only).

>%temp%\vbs.vbs echo wscript.echo weekdayname(Weekday(Now^)^)
for /f "tokens=*" %%1 in ('cscript //nologo %temp%\vbs.vbs') do (
    set day=%%1)
set day=%day:~0,3%

Report •

September 7, 2010 at 18:55:33
It will work if:

set day=%day:~0,3%

Is moved to after the for loop, instead of inside it.

Report •

September 8, 2010 at 00:02:26
Thank you Wahine and Judago,

I tried testing it on my XP machine, and came to the following results:

It is now almost there, but I did not understand how to actually implement Judago's comment! Working out how to do this might resolve the second half of my problem, but.....

What I have now is a day.bat file (to test the script):

%temp%\vbs.vbs echo wscript.echo weekdayname(Weekday(Now^)^)
for /f "tokens=*" %%1 in ('cscript //nologo %temp%\vbs.vbs') do (set day=%%1)
set day=%day:~0,3%
echo Current day is %day%

I put the last line in to display the variable day.

This initially brings up a "Windows Script Host" window with "Wednesday" in it after running the first line, but this requires me to hit "OK" for it to continue
......then it displays:
Current day is day:~0,3
so it looks as though the "set day=%day:~0,3%" has overwritten the extracted day of the week, rather than just extracting the first three characters as desired.

How do I prevent the need for user interaction, and then not overwrite the clever Cscript extraction of the day of the week!!
BUT then I tried it on the Windows 2003 server machine, and had far worse results, as it reported that :
'c:\documen~1\AdminT~1\Locals~1ztemp\2\vbs.vbs' is not recognized as an internal or external command, operable program or batch file.

Does this mean that I am missing something on the Windows 2003 server which is required to run the Cscript?

As you can tell my scripting skills are limited!

Many thanks in anticipation,


Report •

Related Solutions

September 8, 2010 at 00:48:10
but I did not understand how to actually implement Judago's comment!

You don't need to, Wahine edited in the change.

%temp%\vbs.vbs echo wscript.echo weekdayname(Weekday(Now^)^)

Should be:

> %temp%\vbs.vbs echo wscript.echo weekdayname(Weekday(Now^)^)

Report •

September 8, 2010 at 03:45:54
Thanks - that eliminated the "not recognized command" error on the 2003 machine, AND got rid of the pop up window, but I still cannot get the %day% variable.....

This is now the output when I run the Day.bat script on the 2003 machine:


D:\temp>echo wscript.echo weekdayname(Weekday(Now)) 1>C:\DOCUME~1\ADMINT~1\LOCALS~1\Temp\2\vbs.vbs

D:\temp>for /F "tokens=*" %l in ('cscript //nologo C:\DOCUME~1\ADMINT~1\LOCALS~1\Temp\2\vbs.vbs') do (set day %1 )

D:\temp>(set day %1 )

D:\temp>set day=day:~0,3

D:\temp>echo Current day is day:~0,3
Current day is day:~0,3

Any further ideas??



Report •

September 8, 2010 at 03:57:28
I think you may have accidentally introduced a typo, lets play "spot the difference":

for /F "tokens=*" %l ....
... do (set day %1 )

If you make them the same character then I think it just may work ;).

Report •

September 8, 2010 at 04:08:54
I have a semi-related question, are you using substrings on %date% for other values(ie the day, month and week numbers) or do you only need the three letter day?

As you have learnt the "%date%" variable and "date /t" are formatted according to the regional settings. If you need them it's not much more trouble to get those values from vbs as well and they will work on more systems without change.

Report •

Ask Question