How do I make a batch file that can run certain commands based on the date?
How do I make a batch file that can run certain commands based on the date?
I was wondering how to make a batch file that runs a certain command/commands based on the date. I have a script that is based on the day of the week:
IF %DATE:~0,3%==Mon CALL (File/program/directory)
IF %DATE:~0,3%==Tue CALL (File/program/directory)
IF %DATE:~0,3%==Wed CALL (File/program/directory)
IF %DATE:~0,3%==Thu CALL (File/program/directory)
IF %DATE:~0,3%==Fri CALL (File/program/directory)
IF %DATE:~0,3%==Sat CALL (File/program/directory)
IF %DATE:~0,3%==Sun CALL (File/program/directory)
But I need one more specific, like it runs a program on someone's birthday.
Thanks for your help!
I am not just trying to get the job done, I'm expanding my knowledge of batch files.
– Ian
Apr 25 '11 at 23:56
2 Answers
2
If you do it the same way like your current solution, it should be simple.
But it depends on your date/time format.
if "%DATE:~9,5%"=="11/04" call birthdayOfPeter.bat
Thank you for your help. This is very useful information. Do you know where I can get a list of date formats?
– Ian
Apr 26 '11 at 0:08
There is another method to do it.
this code will start your program on 11/02/2014
(edit when ever you want to start)
copy anything.bat
to startup
11/02/2014
anything.bat
type this in anything.bat
:
anything.bat
@echo off
:finddate
if %date% GEQ 11/02/2014 goto start
goto finddate
:start
start "your program"
goto end
:end
Thanks for contributing an answer to Stack Overflow!
But avoid …
To learn more, see our tips on writing great answers.
Required, but never shown
Required, but never shown
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
Just use the task scheduler/AT to run the file?
– Alex K.
Apr 24 '11 at 13:23