loading

How to make a batch file that temporary changes the system date?

Hi, Im looking to make a batch file that will change the system date back to the 1st march 2007, open up a program and then revert it back after say 10 seconds. Would anyone be able to help me on this? Thanks in advance, Mat

sort by: active | newest | oldest
Just thought I might answer to try to help anyone else looking at this.

You could echo the time you want and send the output of the command to the date command. Then, put a delay and revert it. Of course you'd need to put a delay in. so, something like this would work...

set before=%date%
echo 01/03/2007 | date
ping localhost -n 10
echo %before% | date


ty to all.... but the one i only used in the code was the first and second code only because when i tried to copy alll the code, DOS command appeared and ask me for a date....... its maybe due to

ping localhost -n 10
echo %before% | date

NachoMahma8 years ago
spinna22 (author)  NachoMahma8 years ago
would you have any idea on how to put one together... i am really clueless sorry
. It's been a long time since I worked with batch files, but here's an outline: . Read current system datetime into a variable. . Change datetime to whatever you want . Run your program. IIRC, you just type the filename of the app and include any flags/params that need to be passed. Probably need to include path. I think that will return you to the batch file when the app exits, but you may have to use something like CALL. . Set the system datetime to the stored variable plus 10 secs. I'm drawing a complete blank on how to add time.
spinna22 (author)  NachoMahma8 years ago
i have actually found out how to do it. first of all it wouldnt work because of the date format on my computer didnt match the one the batch file was trying to give it (dd-mm-yyyy was the batch format but the computer was dd-mm-yy).

i solved this by clicking run typing intl.cpl and changing my computer date format.

here is my code:

set BEFOREDATE=%date:~%
date 01-03-07
filename.exe
ping -n 10 127.0.0.1 > NUL 2>&1
date %BEFOREDATE%

the ping is just to make a delay...
i put the batch file in the folder where my application was and created a shortcut on my desktop.
I realize that this post is several years old. I figured that if I was looking for the solution to the issue, that others may be looking for the workthrough as well.

So thanks to spinna22's batch file, I was able to modify the code to run as they intended it to run. Here is the code(I named my batch file run.bat):

REM Store systems current time into BEFOREDATE var as mm-dd-yy
SET BEFOREDATE=%date:~4,2%-%date:~7,2%-%date:~10,4%

REM Set the below date to date you wish to roll your system date back to
DATE 01-03-07

REM First param of START command needs empty double quotes
REM Second param of Start command should be absolute path to application
REM IE "C:\Program Files(x86)\directory\filename.exe"
START "" "filename.exe"

REM Cause a delay to allow application to load
PING -n 10 127.0.0.1 > NUL 2>&1

REM Set system date back to current date
DATE %BEFOREDATE%

To use this script you will want to:
-Create the batch file and place it into the applications directory.
-Create a shortcut to this batch file and place it on your desktop.
-Right click the batch files shortcut and select properties.
-On the shortcut tab click the advanced button.
-Place a check mark in the run as administrator check box.
-Click OK to close the advanced properties window.
-Click OK to close the shortcuts properties window.

Presto, you are up and running.

I hope this is helpful,
Tim McCune
. Nice. . I think you would be better off setting the system date format back to what it was and changing what the bat file sends. You may upset some other program that is expecting the date in the old format. It may not be a problem, but why take a chance?
spinna22 (author)  NachoMahma8 years ago
Yes I agree, but the problem is I don't know how to change the date format that the batch file sends.
. "date 01-03-2007" doesn't work?
ijzerboot8 years ago
Thnx for the advice!
I did it like this:

set BEFOREDATE=%date:~%
date 01-04-09
c:\program.exe
pause
date %BEFOREDATE%

But I have little problem: BEFOREDATE is stored as "weekday dd-mm-yy".
Date requires dd-mm-yy without the weekday.
How do I do that?
This worked for me:

:: Preparing Date
SET TODAY=%date:~3,2%-%date:~6,8% (works for the netherlands)
:: DATE is set to 1-4-2009
DATE 1-4-2009
:: check current DATE
DATE /T
c:\program.exe
DATE %TODAY%
END
Ed Collins8 years ago
I had the same problem and this is how I went about solving it: I wrote a quick and dirty BASIC program that: 1) First saves the current date. 2) Changes the system date. (In my case, I need to set it back to 4-21-2008) 3) Launches a batch file. The batch file simply runs the program I wish to run. (This program won't run unless the date is within 30 days of 4-14-2008) 4) After the program loads, execution returns to my BASIC program. My program then pauses for 5 seconds and then changes the system date BACK to the actual date. That's it. My little program then ends. All I have left is a tiny one-line batch file that is open, and the program I need to run. When I'm finally finished using it, I close it, and that terminates the batch file... and all is well with the world. I tried putting ALL of this in a batch file, but I found that after launching the program, execution wasn't returned to the batch file until I closeed the program. That didn't work for me... I wanted the date changed back immediately after my the program loaded.
fwjs288 years ago
why exactly are you planning on doing this?
spinna22 (author)  fwjs288 years ago
ive got a program that has expired but it works fine when the date is changed back