Page 1 of 2
Creating a batch that sets time/date ahead 33 days possible?
Posted: 04 Oct 2013 14:28
by serverdelux
Hi, was wondering if someone had some batch code that would set the windows time/date ahead 33 days with consideration for other regions time format?
The console message would look like this:
Code: Select all
Would you like to set the date ahead 33 days?
A. Yes
B. Exit
Then after it sets the windows date and displays the new date it would say
Code: Select all
Would you like to correctly reset the date?
A. Yes
B. Exit
Thanks for any help
Re: Creating a batch that sets time/date ahead 33 days possi
Posted: 05 Oct 2013 04:02
by foxidrive
serverdelux wrote:Hi, was wondering if someone had some batch code that would set the windows time/date ahead 33 days with consideration for other regions time format?
You want to set the date ahead 33 days and then set it back to today?
If this is just for a single PC then show us what
echo %date% returns on your computer.
You should be aware that some things can break on a computer by doing this - maybe updates and time critical applications, emails will be fubar etc and some security software will not allow the time/date to be reset like this, IIANM.
Re: Creating a batch that sets time/date ahead 33 days possi
Posted: 05 Oct 2013 04:44
by aGerman
with consideration for other regions time format
Virtually impossible. Try to process the output of
date<nulbut be aware of the language dependencies (shows TT-MM-JJ on my German OS).
Also read the registry values
sDate and
iDate in key
HKCU\Control Panel\InternationalRegards
aGerman
Re: Creating a batch that sets time/date ahead 33 days possi
Posted: 05 Oct 2013 05:44
by penpen
Have a look at this thread:
http://www.dostips.com/forum/viewtopic.php?f=3&t=4717It tells you how to compute dates in future/past (+-90 days).
You just have to use the result (+33 days) to set the date.
My first post there was a pure batch solution to get the current date format, but it has bad side effects (the same side effects your code has, as it does the same: mine is only maximizing these side effects). Read my Edit 2 at that post.
This could be used to set the date to +33 days (just use a for /l loop and increase one day per loop...), so you get what you wanted to do.
But i recommend you to use one of the other functions posted there (shorter code with no side effects).
penpen
Re: Creating a batch that sets time/date ahead 33 days possi
Posted: 05 Oct 2013 05:51
by aGerman
penpen
The calculation is not a big deal but the manner you have to pass the new date to the DATE command is
Regards
aGerman
Re: Creating a batch that sets time/date ahead 33 days possi
Posted: 05 Oct 2013 06:13
by penpen
Why should it be a big problem?
Once you have the date format and the needed date, then just use "date <formatted date>".
For example if you are using my solution:
Code: Select all
@echo off
cls
setlocal
call ::initDateFormats
echo SET_DATE_FORMAT = "%SET_DATE_FORMAT%"
echo DATE_FORMAT = "%DATE_FORMAT%"
:: simulated result of the +33 days date computing, function
set /A "DD=01"
set /A "MM=02"
set /A "YY=03"
setlocal enableDelayedExpansion
::get formatted date
set "FORMATTED_DATE=%SET_DATE_FORMAT%"
set "FORMATTED_DATE=!FORMATTED_DATE:DD=%DD%!"
set "FORMATTED_DATE=!FORMATTED_DATE:MM=%MM%!"
set "FORMATTED_DATE=!FORMATTED_DATE:YY=%YY%!"
endlocal & set "FORMATTED_DATE=%FORMATTED_DATE%"
:: set new date
date %FORMATTED_DATE%
endlocal
goto:eof
:initDateFormats
:: rest of this procedures code
penpen
Edit: Corrected a flaw.
Re: Creating a batch that sets time/date ahead 33 days possi
Posted: 05 Oct 2013 06:25
by aGerman
I don't get it
We are able to figure out in which order year month and day are displayed. Also we are able to find the separator. As you know in Germany it is Day, Month, Year with a point as separator.
OK so far. But what about the hyphens you have to use for passing the date to the DATE command? Well you could assume it's always the 3rd character in the format that DATE<NUL shows but I'm not quite certain if that is true for other languages as well.
Regards
aGerman
Re: Creating a batch that sets time/date ahead 33 days possi
Posted: 05 Oct 2013 06:48
by penpen
Regarding to
http://technet.microsoft.com/en-us/library/bb490889.aspx you always can use periods (.), hyphens (-), or slash marks (/).
In addition, all of them worked for all systems (+different languages: only english, german and spanish), on which i had run it, since MS-DOS 5.0 so i don't think it will be changed ever.
penpen
Re: Creating a batch that sets time/date ahead 33 days possi
Posted: 05 Oct 2013 06:54
by aGerman
To be honest I never tested other separators than the hyphen. If those would work as well it's indeed not an issue anymore
Regards
aGerman
Re: Creating a batch that sets time/date ahead 33 days possi
Posted: 05 Oct 2013 14:07
by serverdelux
Thanks guys for your help
I am doing this cause I'm working with an application that is time/date sensitive
So instead of forwarding the clock forward forward 33 days I just want a simple batch to do it automatically then restore actual time
As my first post says the echoed content will just be either Yes or Exit with date being echoed for both 33 days ahead and then reset current day
p.s.
Side projectCan anyone recommend an forum that is helpful with .vbs scripting?
I sometimes save an theme file and when I run it the personalization window opens up in Windows 7
I wanted to attempt to obtain some code to get the personlization window to either not pop up or close after it pops up
Kinda a stupid function that has the personlization window open up when theme/wallpaper backup is run
...lol
Re: Creating a batch that sets time/date ahead 33 days possi
Posted: 05 Oct 2013 15:02
by foxidrive
foxidrive wrote:If this is just for a single PC then show us what echo %date% returns on your computer.
Re: Creating a batch that sets time/date ahead 33 days possi
Posted: 05 Oct 2013 15:29
by serverdelux
Sat 10/05/2013
Re: Creating a batch that sets time/date ahead 33 days possi
Posted: 05 Oct 2013 15:58
by aGerman
Try:
Code: Select all
@echo off &setlocal EnableDelayedExpansion
for /f "tokens=1,2*" %%a in ('reg query "HKCU\Control Panel\International"^|findstr /i "\<[is]Date\>"') do set "%%a=%%c"
echo Would you like to set the date ahead 33 days?
:loop1
echo(
echo A. Yes
echo B. Exit
set "c=" &set /p "c="
if /i "!c!"=="B" exit /b
if /i "!c!" neq "A" goto loop1
call :DaysAdd 33 newDate
date %newDate%
echo(
echo New date: %date%
echo(
echo Would you like to correctly reset the date?
:loop2
echo(
echo A. Yes
echo B. Exit
set "c=" &set /p "c="
if /i "!c!"=="B" exit /b
if /i "!c!" neq "A" goto loop2
call :DaysAdd -33 newDate
date %newDate%
goto :eof
:DaysAdd ByVal_DeltaIn ByRef_NewDateOut
setlocal
for /f "tokens=1-3 delims=%sDate%" %%a in ("%date:* =%") do (
if %iDate%==0 (set /a Month=100%%a%%100,Day=100%%b%%100,Year=10000%%c%%10000) else (
if %iDate%==1 (set /a Day=100%%a%%100,Month=100%%b%%100,Year=10000%%c%%10000) else (
if %iDate%==2 (set /a Year=10000%%a%%10000,Month=100%%b%%100,Day=100%%c%%100)
)))
set /a "a = 14 - Month, a /= 12, b = Year + 4800 - a, c = Month + 12 * a - 3, d = 153 * c + 2"
set /a "d = d / 5 + Day + b * 365 + b / 4 - b / 100 + b / 400 - 1 + %~1"
set /a "e = 4 * d + 3, e /= 146097, f = -e * 146097, f /= 4, f += d"
set /a "g = 4 * f + 3, g /= 1461, h = -1461 * g, h /= 4, h += f, i = 5 * h + 2, i /= 153, Day = 153 * i + 2, Day /= 5"
set /a "Day = -Day + h + 1, Month = -i / 10, Month *= 12, Month += i + 3, Year = e * 100 + g - 4800 + i / 10"
set /a "Month = 10%Month%, Day = 10%Day%"
if %iDate%==0 (set "new=%Month:~-2%%sDate%%Day:~-2%%sDate%%Year%") else (
if %iDate%==1 (set "new=%Day:~-2%%sDate%%Month:~-2%%sDate%%Year%") else (
if %iDate%==2 (set "new=%Year%%sDate%%Month:~-2%%sDate%%Day:~-2%")))
endlocal &set "%~2=%new%" &goto:eof
Under Vista and newer you have to run as Admin.
I wanted to attempt to obtain some code to get the personlization window to either not pop up or close after it pops up
I can't remember I've ever seen it. Does it run in an own process? (Have a look into the Task Manager if it occurs.)
Regards
aGerman
Re: Creating a batch that sets time/date ahead 33 days possi
Posted: 05 Oct 2013 20:56
by foxidrive
Maybe this will work: I have evaluation software running so I can't try it...
Code: Select all
@echo off
set now=%date:~4%
set date1=today
set qty=33
set separator=/
if /i "%date1%" EQU "TODAY" (set date1=now) else (set date1="%date1%")
echo >"%temp%\%~n0.vbs" s=DateAdd("d",%qty%,%date1%)
echo>>"%temp%\%~n0.vbs" d=weekday(s)
echo>>"%temp%\%~n0.vbs" WScript.Echo year(s)^&_
echo>>"%temp%\%~n0.vbs" right(100+month(s),2)^&_
echo>>"%temp%\%~n0.vbs" right(100+day(s),2)^&_
echo>>"%temp%\%~n0.vbs" d
for /f %%a in ('cscript //nologo "%temp%\%~n0.vbs"') do set result=%%a
del "%temp%\%~n0.vbs"
endlocal& (
set "YY=%result:~0,4%"
set "MM=%result:~4,2%"
set "DD=%result:~6,2%"
set "daynum=%result:~-1%"
)
set "day=%MM%%separator%%DD%%separator%%YY%"
date %day%
echo The date is 33 days into the future - %date%
pause
date %now%
echo The date is set back to %date%
pause
Re: Creating a batch that sets time/date ahead 33 days possi
Posted: 05 Oct 2013 22:19
by serverdelux
They both work awesome
Thank you so much
@aGerman
The personlization window?
I should probably look for it as a process or service but to not get it to open at all would be nice