Link to home
Start Free TrialLog in
Avatar of MrMay
MrMay

asked on

batch file

Hello, can I get some help please?
can someone show me a a script for a batch file that gets the current time/date and changes it by one day ahead.
So if the computer's current time is May 15 2015 11:59pm, i need a script that will change that to May 16 2015 1:01am.
And the next day it runs again and it changes it to May 17 2015 1:01am.    The reason why I'm doing this is cause I have a very old program that is custom build and for some strange reason it always freezes at midnight. Some sort of task/job is trying to run at midnight so I'm trying to skip 12:00am.  
thanks for your help.
Avatar of SStory
SStory
Flag of United States of America image

someone has already written a script to get tomorrow's date from a batch file:
https://www.experts-exchange.com/articles/4196/Advanced-Batch-File-Programming-TOMORROW-BAT.html

You could modify it. Instead of:
xcopy /d:%m%-%d%-%y% /l . .. >nul 2>&1 || goto loop

You could do something like:

date  %m%-%d%-%y%
time 01:01:00

Have this run by a Windows job at 11:59pm every day.
Avatar of Bill Prew
Bill Prew

Yes, we could fashion a script like this, not easy in basic DOS BAT script, but VBscript or PowerSheel should be able to handle.  However, there are a few details I'd like to understand better.

You want to run the script just before midnight, and advance the clock by 62 minutes (in your example the clock would change from May 15 2015 11:59pm, to May 16 2015 1:01am).  This seems a little odd, why not just by 2 minutes to "jump over midnight itself?

Also, naturally doing this everyday will slowly result in the time on the compute being more and more inaccurate, isn't that a problem?  Do you also plan to do the opposite, set the clock back the same amount of time at some point the next day?

Does the DOS program need to be running at midnight?  Could another potentially safer approach be to end the DOS program just before midnight, and then restart it just after midnight?

~bp
Avatar of MrMay

ASKER

Hi BillPrew... My mistake... I meant to type 12:01am... I need it to jump 12:00am...  (for from 11:59pm to 12:01am) I can't restarts the dos program. Its constantly being used.
Its fine if the time is offset... not important in this production system.
Of course power shell and other languages are easier.  A programming language like vb.net or c# or whatever would also be easier than a batch file...super simple, but you'd have to know vb.net and compile it.

What I wrote would do what you asked. Just change the line
time 01:01:00
to
time 12:01:00
ASKER CERTIFIED SOLUTION
Avatar of Bill Prew
Bill Prew

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
OK. I make no warranties whatsoever, but the following vb.net program, should work if ran at 11:59:00. Just unzip it and schedule it to run.  Dotnet 2.0 should be installed on the machine. All win 7 machines have that by default.