help please - dos batch file
#1
This works on Windows2000, supplying the variable with the correct day, but I now need it to work on WinXP and its not supplying the variable with a day. Instead the variable is filled with the full current date.
FOR /F "tokens=1" %%i in ('DATE /T') do set today=%%i
IF NOT "%today%"=="Mon" GOTO tuesday
(do something)
GOTO the_end
:tuesday
IF NOT "%today%"=="Tue" GOTO wednesday
(do something)
GOTO the_end
:wednesday
(do something)
:the_end
I'd really appreciate any help on solving this.
FOR /F "tokens=1" %%i in ('DATE /T') do set today=%%i
IF NOT "%today%"=="Mon" GOTO tuesday
(do something)
GOTO the_end
:tuesday
IF NOT "%today%"=="Tue" GOTO wednesday
(do something)
GOTO the_end
:wednesday
(do something)
:the_end
I'd really appreciate any help on solving this.
#2
XP doesn't display the date in that format by default.
Whent the batch file performs "date /t" it only gets back 15/10/2003 which is why its failing.
The only way I can find to solve it is to customise the English UK language setting.
Control Panel (Classic view)
Regional and Langauage Options
English (United Kingdom) -- "Customize" button
Date tab
Find the short date format and change it
from dd/MM/yyyy
to ddd dd/MM/yyyy
Apply and ok.
date /t now returns the same format as Win2K and your batch file will work.
Alternatively, do it in vbs. It's the future
Some pretty powerful stuff on Technet Script Center.
Whent the batch file performs "date /t" it only gets back 15/10/2003 which is why its failing.
The only way I can find to solve it is to customise the English UK language setting.
Control Panel (Classic view)
Regional and Langauage Options
English (United Kingdom) -- "Customize" button
Date tab
Find the short date format and change it
from dd/MM/yyyy
to ddd dd/MM/yyyy
Apply and ok.
date /t now returns the same format as Win2K and your batch file will work.
Alternatively, do it in vbs. It's the future
Some pretty powerful stuff on Technet Script Center.
#3
Thanks for that. I managed to get my hands on this code if its of any interest...
@echo off
if {%5}=={} @echo Syntax: Call day yyyy mm dd daynumb daytext&goto :EOF
setlocal
set montabl=0033614625035
set monleap=0623614625035
set daytab=7Sunday###1Monday###2Tuesday##3Wednesday4Th ursday#5Friday###6Saturday#
set /a century=1
set /a century4=1
set /a yyyy=%1
set /a mm=100%2%%100
set /a dd=100%3%%100
set /a leap=%yyyy%%%4
if %leap% EQU 0 set /a century=%yyyy%%%100
if %century% EQU 0 set /a century4=%yyyy%%%400
if %leap% EQU 0 set montabl=%monleap%
set /a day=%yyyy% + (%yyyy% / 4)
set /a day=%day% - (%yyyy% / 100)
set /a day=%day% + (%yyyy% / 400)
set /a day=%day% + %dd%
call set /a mon=%%montabl:~%mm%^,1%%
set /a day=%day% + %mon% - 1
set /a day=%day%%%7
set /a day=%day% * 10
if %century% EQU 0 if %century4% NEQ 0 if %mm% LSS 3 set daytab=1Monday###2Tuesday##3Wednesday4Thursday#5Fr iday###6Saturday#7Sunday###
call set w5=%%daytab:~%day%^,10%%
set /a daynumb=%w5:~0,1%
set daytext=%w5:~1,9%
set daytext=%daytext:#=%
endlocal&set %4=%daynumb%&set %5=%daytext%
useage: call filename.bat <year> <month> <day> var_daynum var_dayname
this code should be pretty much universal across all windows platforms, so no need to enter control panel, etc...
[Edited by Lisan Obelisk - 10/16/2003 3:43:18 PM]
@echo off
if {%5}=={} @echo Syntax: Call day yyyy mm dd daynumb daytext&goto :EOF
setlocal
set montabl=0033614625035
set monleap=0623614625035
set daytab=7Sunday###1Monday###2Tuesday##3Wednesday4Th ursday#5Friday###6Saturday#
set /a century=1
set /a century4=1
set /a yyyy=%1
set /a mm=100%2%%100
set /a dd=100%3%%100
set /a leap=%yyyy%%%4
if %leap% EQU 0 set /a century=%yyyy%%%100
if %century% EQU 0 set /a century4=%yyyy%%%400
if %leap% EQU 0 set montabl=%monleap%
set /a day=%yyyy% + (%yyyy% / 4)
set /a day=%day% - (%yyyy% / 100)
set /a day=%day% + (%yyyy% / 400)
set /a day=%day% + %dd%
call set /a mon=%%montabl:~%mm%^,1%%
set /a day=%day% + %mon% - 1
set /a day=%day%%%7
set /a day=%day% * 10
if %century% EQU 0 if %century4% NEQ 0 if %mm% LSS 3 set daytab=1Monday###2Tuesday##3Wednesday4Thursday#5Fr iday###6Saturday#7Sunday###
call set w5=%%daytab:~%day%^,10%%
set /a daynumb=%w5:~0,1%
set daytext=%w5:~1,9%
set daytext=%daytext:#=%
endlocal&set %4=%daynumb%&set %5=%daytext%
useage: call filename.bat <year> <month> <day> var_daynum var_dayname
this code should be pretty much universal across all windows platforms, so no need to enter control panel, etc...
[Edited by Lisan Obelisk - 10/16/2003 3:43:18 PM]
Thread
Thread Starter
Forum
Replies
Last Post