1.

Solve : using date command, just need day?

Answer»

I'm creating a batch file to run as a scheduled task. However, I need to find out how to write the command line to say if TODAY is MONDAY run this command. If today is tuesday, run this command.

Can I do this without if/then statements? How can I truncate the date so only Mon, Tue, Wed, etc. shows up? I only care about the day of the week, not the actual date. :-/You didn't mention your OS, so I can only guess. There are multiple ways to do this. TRY this one:

set dow=%date:~0,3%

If your OS doesn't support that, try:

for /f %%a in ('date /t') do set dow=%%a

Hope this helps. Both COMMANDS worked good. I'm using XP.

Here's another issue...

I would like to say if dow = Mon then command. However, it's not working. Sample:

set dow=%date:~0,3%1

if %dow% == Mon1 goto Monday
if %dow% == Tue1 goto Tuesday
if %dow% == Wed1 goto Wednesday
if %dow% == Thu1 goto Thursday
if %dow% == Fri1 goto Friday

:Monday
set message = Today is Monday

:Tuesday
set message = Today is Tuesday

:Wednesday
set message = Today is Wednesday

:Thursday
set message = Today is Thursday

:Firday
set message = Today is Friday
pause

When I run the batch, the only thing that works is the variable is set. Help....I'm new!!I'm pretty sure you can't have spaces before/after the double equals.

There is another way you might consider:

Code: [Select]
@echo off
goto %date:~0,3%

:mon
echo Today is Monday
.
.
goto somewhere

:tue
echo Today is Tuesday
.
.
goto somewhere


You need to branch around your labels otherwise your logic will fall thru all the other labels.

Hope this helps.



Discussion

No Comment Found