I am trying to find out the day of the week using a batch file in the command prompt. the date /t command just displays the date 07/11/2005. Does anyone know any way I can find out the day (whether its Mon-Sun)?
Thanks
The date /t, which is the same as: echo %DATE%
output style depends on your settings.
Mine shows:
Mon 07-11-2005
Since your shows 07/11/2005, it will be a trick to get a batch to show DOW.
If at first you don't succeed, you're about average.M2
Thanks for the reply. Unfortunately I can't go changing the settings for how the date is displayed so theirs only 1 other option I can think of.
Not sure if it'll work right or not, or what other problems it might cause, but I might try using a "start" date, maybe Monday 1st August 2005, and then try subtracting that date from the current date, and using "modulus 7". Then comparing the remainder to check for the day. If the result = 0 then it would be a Monday, 1 Tuesday etc. Hopefully that will work maybe, if it does I'll post it on here in case anyone else ends up with a similar situation.
I could use a start date like Tuesday 1st November I suppose, but that would make 0 equal Tuesday, so just seems friendlier to use a start date, which is on a Monday.
I'll probably have to take into account leap years as well, but as the next one is not until 2008 I've got plenty of time to fix that problem :-)
There have been a few recent threads on "date math' which is a can of worms at best. dtech10 seems to have hammered it out. I haven't had the courage to plow through his code.
Since you requirement is "only" for DOW, you might use a "lookup table". Not elegant, but effective.
If at first you don't succeed, you're about average.M2
OBW, One snag to be aware of is that 0n is seen by CMD as an octal number so 08 and 09 are no-go.
C:\temp\-\31>set /a x=08%7
Invalid number. Numeric constants are either decimal (17),
hexadecimal (0x11), or octal (021).
If at first you don't succeed, you're about average.M2
About the DOW problem... Win 2000 displays the current date by heading with the Day of Week, but Win XP gives you the bare date in your country format without DOW. This is one of the little annoiances affecting the two (almost) brothers operating sysyems.
To work around the trick is to force the legacy format displayed by (emulated) DOS
Echo.|Command /C Date|Find "current"
Please verify "current" as I'm running an Italian edition of XP and obviously "current" sounds "corrente" in my language.
Hi IVO, You're the man.
And you're correct about the verbage.
Note that this bat sets the var DOW and depends only on skipping the correct number of chars, in this case 16.
:: setDOW.bat
@echo offEcho.|Command /C Date>DOW
set /p today=<DOW
set DOW=%today:~16,3%
echo DOW=%DOW%
:: DONEAn inquiring mind might wonder why command.com transposes MM & DD.
But hey, IT'S WINDERS.
If at first you don't succeed, you're about average.M2
Thanks guys, you're all the best! Just a few questions if you don't mind, sorry if they're really stupid.
Why is it that if after the command "Echo.|Command /C Date>DOW" I then put in the following line "echo DOW=%DOW%" in order to see the value of DOW at that point, it appears to be empty? Shouldn't it contain the following
"Current date is Mon 07/11/2005
Enter new date (dd-mm-yy):"
which is basically the output of the "Echo.|Command /C Date" command?Also, with the ~16,3 I assume the position counting starts at 0?
Thanks again for all your help.
The only dumb question is the one that doesn't get asked. At that point the DOW var IS empty.
This line:
Echo.|Command /C Date>DOW
sends the output into a file named DOW.
This line sets the var TODAY to the contents of the file DOW. But only the first line because the "line break" [CRLF] ends the var string.
This line:
set DOW=%today:~16,3%
sets the var DOW to a substring of the var TODAY.
In this case 16,3 means: skip 16 chars and use the next 3.
If at first you don't succeed, you're about average.M2
| « Multiboot XP vs. 2K SRV | CD Player in Computer not... » |