Log in

View Full Version : Setting the date via cli


juGGaKNot
18th January 2010, 00:04
I need a way to set the pc date to a specific date while encodig, something like :

1 : get the current date ( day,month,year ) and store it.
2 : set the date to ( 10.01.2010 )
3 : after encoding is done reset the date ( 10.01.2010 ) to the first stored date.

Something that works for xp and windows 7 if possible.

Thnx, cheers.

juGGaKNot
18th January 2010, 20:34
Any hints ?

stax76
18th January 2010, 21:55
How about that?: http://ss64.com/nt/date.html

LoRd_MuldeR
18th January 2010, 22:05
http://msdn.microsoft.com/en-us/library/ms724338(VS.85).aspx
http://msdn.microsoft.com/en-us/library/ms724936(VS.85).aspx

Setting the time will require elevated privileges (UAC dialog!) on Windows 7 though.

juGGaKNot
18th January 2010, 23:29
How about that?: http://ss64.com/nt/date.html

Thnx.

http://msdn.microsoft.com/en-us/library/ms724338(VS.85).aspx
http://msdn.microsoft.com/en-us/library/ms724936(VS.85).aspx

Setting the time will require elevated privileges (UAC dialog!) on Windows 7 though.

Thnx also but learning c .. seems hard ( or maybe just the maing it into an exe part )

@echo off
DATE /T > time.txt
set /p mytime=<"time.txt"
pause
DATE 12-12-2009
cls
echo Current date is : %mytime%
echo.
echo Date has been set to :
DATE /T
echo.
echo Until the bat finishes.
pause
DATE %mytime%

Seems to work, just have to use grep to extract the old date from the text file

Sat 12/12/2009

DATE %mytime% does not work ( have to remove Sat )

juGGaKNot
21st January 2010, 11:12
I'm having some problems with the date restore, any hints ?

@echo off
FOR /F “TOKENS=1* DELIMS= ” %%A IN (’DATE/T’) DO SET CDATE=%%B
FOR /F “TOKENS=1,2 eol=/ DELIMS=/ ” %%A IN (’DATE/T’) DO SET mm=%%B
FOR /F “TOKENS=1,2 DELIMS=/ eol=/” %%A IN (’echo %CDATE%’) DO SET dd=%%B
FOR /F “TOKENS=2,3 DELIMS=/ ” %%A IN (’echo %CDATE%’) DO SET yyyy=%%B
SET xxx=%mm%%dd%%yyyy%
DATE 12-12-2009
DATE /T > time2.txt
set /p mytime2=<"time2.txt"
del "time.txt"
del "time2.txt"
cls
echo Date is : %mytime%, Date was set to %mytime2% until the bat finishes.
pause
DATE %xxx%
pause

Found the restore script here

http://www.tech-recipes.com/rx/956/windows-batch-file-bat-to-get-current-date-in-mmddyyyy-format/